0

I'm trying to find out how to properly document an array property in a class for phpdocumentor.

Ex:

<?php
class foo {
   /**
    * This holds something important
    * @var string
    */
    protected $junk;
   /**
    * This holds an important array of strings
    * @var ???????
    */
    protected $stuff = array();
    // ...
}
?>

I couldn't find anything in the phpdoc manual about array properties.

hakre
  • 193,403
  • 52
  • 435
  • 836
James L.
  • 4,032
  • 1
  • 15
  • 15
  • 3
    Have you tried `* @var string[]` ? See as well: [PHPDoc type hinting for array of objects?](http://stackoverflow.com/q/778564/367456) – hakre Mar 03 '12 at 21:37
  • In netbeans, it seems to accept the @var string[]. Thanks – James L. Mar 03 '12 at 21:49
  • 1
    But you have asked for PHPDocumentor, not Netbeans. – hakre Mar 03 '12 at 21:55
  • Well, there are about 30 properties in the parent class and only one is an array. In the multiple classes extending the parent I can quickly see what I'm dealing with. – James L. Mar 03 '12 at 21:57
  • I'm hoping it will work with both.. will let you know soon if PHPDocuemntor accepts this – James L. Mar 03 '12 at 21:59
  • What additional features do you get when typing a property as an array with neatbeans? Since arrays in PHP aren't objects you don't get any autocomplete. What do you mean if PHPDoc accepts it? `array` is the official data-type of PHP. `gettype()` returns `array` not `string[]` – Mike B Mar 03 '12 at 22:01
  • Mike, after some reading, you are correct: @var array is what is suggested in Zandstra's OOP PHP book, and it works. However, "array" was NOT listed as an option in the documentation for PHPDocumentor. What I meant by "accept" is whether or not PHPDocumentor would successfully parse my comments and turn them into an HTML version without throwing errors. – James L. Mar 03 '12 at 22:15

1 Answers1

2

/** @var array */ for your protected $stuff is the proper syntax. The phpDocumentor manual page for @var shows "The datatype should be a valid PHP type (int, string, bool, etc),", and "array" is such a valid PHP type.

Some IDEs have also begun recognizing /** @var ElementType[] */ to indicate "this is an array, whose elements are all of type ElementType". This syntax will be available in an upcoming version of phpDocumentor.

Gricey
  • 1,321
  • 1
  • 18
  • 38
ashnazg
  • 6,558
  • 2
  • 32
  • 39