use 'CachingIterator::TOSTRING_USE_INNER' flag
<?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;
/*
output:
toString this class
*/
?>