ID: 46958
Updated by: [email protected]
Reported By: [email protected]
-Status: Bogus
+Status: Open
Bug Type: SPL related
Operating System: Mac OS X 10.5.6 PPC
PHP Version: 5.2.8
New Comment:
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
)
Previous Comments:
------------------------------------------------------------------------
[2008-12-29 02:44:48] [email protected]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
Your keys are conflicting, so the second Iterator is overwriting the
keys of the first iterator, then the 3rd overwrites hem. Use the secnd
parameter for iterator_to_array()
------------------------------------------------------------------------
[2008-12-28 04:12:05] [email protected]
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
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46958&edit=1