I have a class Foo, I need to do :
$foo = new Foo();
foreach($foo as $value)
{
echo $value;
}
and define my own method to iterate with this object, exemple :
class Foo
{
private $bar = [1, 2, 3];
private $baz = [4, 5, 6];
function create_iterator()
{
//callback to the first creation of iterator for this object
$this->do_something_one_time();
}
function iterate()
{
//callback for each iteration in foreach
return $this->bar + $this->baz;
}
}
Can we do that? How?