A little test about the function call order:
<?php
class TestIterator extends IteratorIterator
{
public function key()
{
echo __FUNCTION__, PHP_EOL;
return parent::key();
}
public function next()
{
echo __FUNCTION__, PHP_EOL;
return parent::next();
}
public function rewind()
{
echo __FUNCTION__, PHP_EOL;
return parent::rewind();
}
public function valid()
{
echo __FUNCTION__, PHP_EOL;
return parent::valid();
}
}
class TestFilterIterator extends FilterIterator
{
public function accept()
{
echo __FUNCTION__, PHP_EOL;
return true;
}
}
$iterator = new ArrayIterator(array('a', 'b', 'c'));
foreach (new TestFilterIterator(new TestIterator($iterator)) as $k => $v) {
echo PHP_EOL;
}
?>
This will output the following:
rewind
valid
key
accept
next
valid
key
accept
next
valid
key
accept
next
valid