Php

Asked • 06/05/19

PHPDoc type hinting for array of objects?

So, in PHPDoc one can specify `@var` above the member variable declaration to hint at its type. Then an IDE, for ex. PHPEd, will know what type of object it's working with and will be able to provide a code insight for that variable. <?php class Test { /** @var SomeObj */ private $someObjInstance; } ?> This works great until I need to do the same to an array of objects to be able to get a proper hint when I iterate through those objects later on. So, is there a way to declare a PHPDoc tag to specify that the member variable is an array of `SomeObj`s? `@var` array is not enough, and `@var array(SomeObj)` doesn't seem to be valid, for example.

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.