To know that you are with the with "Array of Foo" and you want to ensure methods receive "Array of Foo", then use this:
class ArrayOfFoo extends \ArrayObject {
public function offsetSet($key, $val) {
if ($val instanceof Foo) {
return parent::offsetSet($key, $val);
}
throw new \InvalidArgumentException('Value must be a Foo');
}
}
Then:
function workWithFoo(ArrayOfFoo $foos) {
foreach ($foos as $foo) {
// etc.
}
}
$foos = new ArrayOfFoos();
$foos[] = new Foo();
workWithFoo($foos);
You have to define a new "type" of "array of foo", then pass that "type" around using type hinting protection.
I hope this helps you.