10

I use PhpDocumentor2 for generating documentation. I searched for this subject but I can't find specific rule for it. For Example I have class which name is AddressField and I want to specify my $addressFields as array of AddressField objects.

/**
 * @var AddressField[]
 */
private $addressFields;
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
  • @Jack I examined this question but I can't find answer to my question – Farid Movsumov Nov 19 '12 at 14:17
  • If this [Eclipse thread](http://stackoverflow.com/questions/778564/phpdoc-type-hinting-for-array-of-objects) is to be believed, your syntax should work in future :) – Ja͢ck Nov 19 '12 at 14:22
  • 1
    To the best of my knowledge, the format you show above is correct. Its just not widely supported. I do know that PHPStorm uses that format at least. – Wige Nov 19 '12 at 14:22
  • 2
    @Jack I'm from the future and I can confirm your comment. It works nowadays. – Robin van Baalen May 15 '14 at 21:43

1 Answers1

24

phpdoc themselves describe the use of arrays here:

1.4.4. Arrays

  • undefined: @return array
  • single type: @return int[]
  • multi type: @return (int|string)[]

The same should apply to variable definitions:

/* @var Type[] $arr */
schmijos
  • 8,114
  • 3
  • 50
  • 58