Clone FilterIterator/IteratorIterator?
| From: | Peter Oberst | Date: | Mon, 24 Mar 2014 20:37:26 +0000 |
| Subject: | Clone FilterIterator/IteratorIterator? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-323104@lists.php.net to get a copy of this message | ||
Hi,
I want to use an Iterator that returns an the inner iterator, with an
additional FilterIterator applied.
The returned iterator should be separated from my inner iterator, to
avoid errors like 'ArrayIterator::next(): Array was modified outside'.
To avoid this, I think it might be the best to simply clone the inner iterator.
Unfortunatly, if the innerIterator is an FilterIterator, so cloning
will throw an exception:
PHP Fatal error: Call to undefined method ArrayIterator::getIterator()
Is there a good reason why i can't clone a FilterIterator?
Testcase:
<?php
class MyIterator extends FilterIterator {
public function accept() {
return true;
}
}
$arr = new ArrayObject(array());
$it1 = new MyIterator($arr->getIterator());
$it2 = $it1->getIterator();