How can I specify array of objects in PhpDoc

13,860

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 */
Share:
13,860
Farid Movsumov
Author by

Farid Movsumov

If my insights helped you or your organization, buy me a ☕. Founder of Botmake.io 🤖

Updated on July 28, 2022

Comments

  • Farid Movsumov
    Farid Movsumov almost 2 years

    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;
    
  • gskema
    gskema about 7 years
    You may also write int[]|string[]
  • Jens Kohl
    Jens Kohl almost 7 years
    There is also a proposed PSR: PSR-5: PHPDoc on Arrays