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;
4
  • @Jack I examined this question but I can't find answer to my question Commented Nov 19, 2012 at 14:17
  • If this Eclipse thread is to be believed, your syntax should work in future :) Commented Nov 19, 2012 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. Commented Nov 19, 2012 at 14:22
  • 2
    @Jack I'm from the future and I can confirm your comment. It works nowadays. Commented May 15, 2014 at 21:43

1 Answer 1

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 */
Sign up to request clarification or add additional context in comments.

2 Comments

You may also write int[]|string[]
There is also a proposed PSR: PSR-5: PHPDoc on Arrays

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.