|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75155 AppendIterator::append() is broken when appending another AppendIterator
Submitted: 2017-09-04 15:22 UTC Modified: 2017-09-05 08:53 UTC
From: bschussek at gmail dot com Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 7.1.9 OS: ubuntu 16.04 LTS
Private report: No CVE-ID: None
 [2017-09-04 15:22 UTC] bschussek at gmail dot com
When passing another AppendIterator to AppendIterator::append(), the entire AppendIterator is returned during iteration instead of the individual entries.

Test script:

$array_a = new ArrayIterator(array('a', 'b', 'c'));
$array_b = new ArrayIterator(array('d', 'e', 'f'));

$iterator = new AppendIterator;

$iterator2 = new AppendIterator;

foreach ($iterator2 as $current) {
    echo $current;

Expected result:

Actual result:
PHP Catchable fatal error:  Object of class ArrayIterator could not be converted to string


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-04 16:05 UTC]
-Status: Open +Status: Verified
 [2017-09-04 16:05 UTC]
New to 7.1.9 and apparently created during the fix for bug #74977.
 [2017-09-04 19:28 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-09-05 08:22 UTC] codronm+circlecode at gmail dot com
please note that from 7.1.7 to 7.1.8,the behavior also changed:
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-05 08:53 UTC]
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

  while ($it->valid()) {
    $key = $it->key();
    $value = $it->current();

Adding the ->rewind() gives the correct behavior.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 07:01:31 2024 UTC