关于函数调用顺序的小测试
<?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;
}
?>
这将输出以下内容
rewind
valid
key
accept
next
valid
key
accept
next
valid
key
accept
next
valid