使用 'CachingIterator::TOSTRING_USE_INNER' 标志
<?php
class A extends ArrayIterator {
public function __toString(){
return 'toString this class';
}
}
$iterator = new A(array('apple'=>10, 'banana'=>20, 'cat'=>30));
$cache = new CachingIterator($iterator, CachingIterator::TOSTRING_USE_INNER);
$cache->next();
$cache->next();
echo $cache;
/*
输出:
toString this class
*/
?>