I’m not sure what exactly PHPDoc type hint should be for a variable that is either array or an object that can act like an array? I have come up with some ideas but I’m not 100% sure about them:
The param has to be an array or an object that can be used in foreach:
/**
* @param array|Traversable $subscribers
*/
The param has be be an array or an object that can use all ArrayAccess features like foreach, count(), square bracket element access, etc.:
I’m not sure whether this is just a phpstorm thing or what, but I can tell you if you have an array of say $player objects, and you wanted to have code hinting work on the foreach loop, you can use a phpdoc syntax like this:
/**
*@var $players Player[]
*/
foreach($players as $player){
$player-> //the moment you do this in php storm, you'll get code hinting to all the public methods in a Player object
}
Again, I’m not sure whether this is just a phpstorm thing, but I do it all the time because I find it very useful.
I use Netbeans and this works but with a slight modification:
/* @var $players Player[] */
I can also do this for parameter hints:
/**
* @param Subscriber[] $subscribers
*/
This is nice, I didn’t know about it! However, it only partially answers my question, because this case only covers a collection of objects. Can I describe collections of other data types in the same way? Like this: