Declaring a collection of objects as return type is not implemented and forbidden:
<?php
class Child{}
function getChilds(): Child[]
{
return [(new Child()), (new Child())];
}
var_dump(getChilds());
// Returns: Parse error: syntax error, unexpected '[', expecting '{'
?>
We have to use:
<?php
class Child{}
function getChilds(): array
{
return [(new Child()), (new Child())];
}
var_dump(getChilds());
// Returns:
/*
array (size=2)
0 =>
object(Child)[168]
1 =>
object(Child)[398]
*/
?>
Idem for function parameter:
<?php
function setChilds(Child[] $childs){}
// Not allowed
function setChilds(array $childs){}
// Allowed
?>