you can also
$arrYourObjectType = new YourObjectType[];
Then if the object array is your return type for the function, in your phpdoc, to type hint the return value, in the phpdoc above your function:
/**
* @param $whatever
* @return array ...$arrYourObjectType
**/
public function someFunction($whatever){
$arrYourObjectType[] = new YourObjectType[];
$x=0;
foreach($arrValues as $value)
{
$objYourObjectType = new YourObjectType();
$objYourObjectType->setSomething($value[0])
->setSomethingElse($value[1]);
(and so on)
//we had to set the first element to a new YourObjectType so the return
//value would match the hinted return type so we need to track the
//index
$arrYourObjectType[$x] = $objYourObjectType;
$x++;
}
return $arrYourObjectType;
}
Then in IDE's such as php storm, when using a class containing that function the return value of the function will be treated like an array of your object (properly hinted) and the IDE will expose the object methods on each element of the object array properly.
You can do things easy/dirty without all this, but phpStorm won't hint the methods on the elements of your object array properly.
If feeding an array of YourObjectType to a function...
/**
*@param YourObjectType ...$arrYourObjectType
**/
public function someFunction(YourObjectType...$arrYourObjectType){
foreach($arrYourObjectType as $objYourObject)
{
$someval = $objYourObject->getSomething();//will be properly hinted in your ide
}
}
It's all about the ellipses when feeding and retrieving object arrays :-)
Edit: I had a few things wrong with this because I did it from memory... corrected... Sorry bout this...