Bug #75155 [Csd]: AppendIterator::append() is broken when appending another AppendIterator

From: Date: Tue, 05 Sep 2017 08:53:12 +0000
Subject: Bug #75155 [Csd]: AppendIterator::append() is broken when appending another AppendIterator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210956@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75155&edit=1 ID: 75155 Updated by: requinix@php.net Reported by: bschussek at gmail dot com Summary: AppendIterator::append() is broken when appending another AppendIterator Status: Closed Type: Bug Package: SPL related Operating System: ubuntu 16.04 LTS PHP Version: 7.1.9 Assigned To: nikic Block user comment: N Private report: N New Comment: That's probably due to changes from #73471, however you're not quite following the contract: when iterating manually you need to call ->rewind() beforehand. foreach ($it as $key => $value) { ... } translates to $it->rewind(); while ($it->valid()) { $key = $it->key(); $value = $it->current(); ... $it->next(); } Adding the ->rewind() gives the correct behavior. Previous Comments: ------------------------------------------------------------------------ [2017-09-05 08:22:20] codronm+circlecode at gmail dot com please note that from 7.1.7 to 7.1.8,the behavior also changed: https://3v4l.org/EN75q not sure this is related to the exact same bug (for which I was creating a report during the same time as this one appeared) or if this should be another one ------------------------------------------------------------------------ [2017-09-04 19:28:50] nikic@php.net I've reverted the patch for bug #74977 for now. https://github.com/php/php-src/commit/b689857d53177b6027679f67fecbde8f36c174d1 https://github.com/php/php-src/commit/c2e3541cc1200f38f72deccac66d889888e3949d ------------------------------------------------------------------------ [2017-09-04 19:27:41] nikic@php.net Related To: Bug #74977 ------------------------------------------------------------------------ [2017-09-04 16:05:13] requinix@php.net New to 7.1.9 https://3v4l.org/egvFW and apparently created during the fix for bug #74977. ------------------------------------------------------------------------ [2017-09-04 15:22:02] bschussek at gmail dot com Description: ------------ When passing another AppendIterator to AppendIterator::append(), the entire AppendIterator is returned during iteration instead of the individual entries. Test script: --------------- <?php $array_a = new ArrayIterator(array('a', 'b', 'c')); $array_b = new ArrayIterator(array('d', 'e', 'f')); $iterator = new AppendIterator; $iterator->append($array_a); $iterator2 = new AppendIterator; $iterator2->append($iterator); $iterator2->append($array_b); foreach ($iterator2 as $current) { echo $current; } Expected result: ---------------- abcdef Actual result: -------------- PHP Catchable fatal error: Object of class ArrayIterator could not be converted to string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75155&edit=1

« previous php.bugs (#210956) next »