|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-28 04:12 UTC] pestilence669@php.net
Description:
------------
The SPL iterator_to_array() function does not appear to include every
inner iterator contained within an AppendIterator. It seems that it only
processes the very last iterator that was appended.
I'd expect that array conversion would parallel the traversal of
foreach, but it does not. To maintain consistency within SPL itself, I'd
suggest that this be corrected.
If the behavior can be confirmed, I'm willing to supply the patch &
regression tests. I'd like more karma.
I've also verified this w/ version 5.2.6 on the same platform and
version 5.2.3-1ubuntu6 on x86 32-bit Linux.
Reproduce code:
---------------
<?php
$r = new AppendIterator();
$r->append(new ArrayIterator(array(1,2)));
$r->append(new ArrayIterator(array(3,4)));
$r->append(new ArrayIterator(array(5,6)));
// only sees 5 and 6:
print_r(iterator_to_array($r));
// this works as expected: foreach ($r as $i) echo $i;
?>
Expected result:
----------------
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Actual result:
--------------
Array
(
[0] => 5
[1] => 6
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 04:00:01 2025 UTC |
Still doesn't work as expected: php -r '$a = new AppendIterator(); $a->append(new ArrayIterator(array(1,2))); $a->append(new ArrayIterator(array(3,4))); print_r(iterator_to_array($a), false);' Array ( [0] => 3 [1] => 4 )Bad paren. My bad. Works. php -r '$a = new AppendIterator(); $a->append(new ArrayIterator(array(1,2))); $a->append(new ArrayIterator(array(3,4))); print_r(iterator_to_array($a, false));' Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )