Bug #49104 [Com]: AppendIterator::append($iterator) calls $iterator->rewind() with no reason

From: Date: Wed, 23 Mar 2011 17:32:47 +0000
Subject: Bug #49104 [Com]: AppendIterator::append($iterator) calls $iterator->rewind() with no reason
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159730@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=49104&edit=1 ID: 49104 Comment by: demjan at kaluzki dot de Reported by: seva dot lapsha at gmail dot com Summary: AppendIterator::append($iterator) calls $iterator->rewind() with no reason Status: Assigned Type: Bug Package: SPL related Operating System: * PHP Version: 5.3.0 Assigned To: colder Block user comment: N Private report: N New Comment: The rewind is invoked only on the first appended (not empty) inner-iterator. workaround: $workaround = new ArrayIterator(array('delete_me_after_all_append_calls_are_done')); $a = new ArrayIterator(array('a', 'b')); $b = new ArrayIterator(array('c', 'd')); $append = new AppendIterator(); $append->append($workaround); // invokes implicit: // $workaround->rewind(); // $workaround->valid(); // $workaround->current(); // $workaround->key(); // $workaround->rewind(); $append->append($a); $append->append($b); unset($workaround[0]); // no further append calls are allowed, // otherwise it seems to hang up in infinite loop Previous Comments: ------------------------------------------------------------------------ [2009-07-29 22:57:40] seva dot lapsha at gmail dot com Line 6: x This causes append to happen twice: should be read as * This causes rewind to happen twice:) ------------------------------------------------------------------------ [2009-07-29 22:54:19] seva dot lapsha at gmail dot com Description: ------------ AppendIterator::append($iterator) calls $iterator->rewind() with no reason. This causes append to happen twice: 1) when $iterator appended; 2) when $iterator starts iterating. Reproduce code: --------------- <?php class ArrayIterator1 extends ArrayIterator { function rewind() { echo "."; parent::rewind(); } } $i1 = new ArrayIterator1(array(1, 2, 3)); $i2 = new ArrayIterator1(array(4, 5, 6)); $i = new AppendIterator(); $i->append($i1); $i->append($i2); foreach ($i as $n) { echo $n; } ?> Expected result: ---------------- .123.456 rewind() of each append()ed iterator should be called on demand when iterating and not when append()ing. Actual result: -------------- ..123.456 On each append() each append()ed iterator's rewind is called with no need. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=49104&edit=1

« previous php.bugs (#159730) next »