|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-09-04 15:22 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 06:00:01 2025 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 $it->rewind(); while ($it->valid()) { $key = $it->key(); $value = $it->current(); ... $it->next(); } Adding the ->rewind() gives the correct behavior.