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.
The problem is that
@var
can just denote a single type - Not contain a complex formula. If you had a syntax for "array of Foo", why stop there and not add a syntax for "array of array, that contains 2 Foo's and three Bar's"? I understand that a list of elements is perhaps more generic than that, but it's a slippery slope.Personally, I have some times used
@var Foo[]
to signify "an array of Foo's", but it's not supported by IDE's.