ArrayObject IteratorAggregate, . . , , ,
class Foo
{
private $array = [1,2,3,4];
}
foreach Foo, :
foreach (new Foo as $bar) {
echo $bar;
}
Iterator, . , , , , , . Iterator IteratorAggregate
class Foo implements IteratorAggregate
{
private $array = [1,2,3,4];
public function getIterator()
{
return new ArrayIterator($this->array);
}
}
, foreach, PHP Iterator, getIterator Foo, 1234.
ArrayObject foreach ArrayObject. , getIterator , , Iterator .
ctor- ArrayObject:
public __construct (
[ mixed $input
[, int $flags = 0
[, string $iterator_class = "ArrayIterator"
]]] )
, .