Bug #64643 [Opn->Csd]: MultipleIterator and its not scalar keys
Edit report at https://bugs.php.net/bug.php?id=64643&edit=1
ID: 64643
Updated by: nikic@php.net
Reported by: mikolaj dot kopras at vexillium dot org
Summary: MultipleIterator and its not scalar keys
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: Ubuntu 2.6.38-15-generic x86_64
PHP Version: 5.4.14
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
This issue is already fixed in PHP 5.5, where array keys will be allowed for iterators.
Previous Comments:
------------------------------------------------------------------------
[2013-04-13 16:55:05] mikolaj dot kopras at vexillium dot org
Description:
------------
The idea of MultipleIterator is great, however its key() method implementation is
somehow invalid. Documentation of Iterator::key clearly stands, that key have to
be a scalar or NULL, but MultipleIterator returns an array which leads to
problems.
First problem is inability to use $key => $val syntax in foreach
Second problem is inability to use MultipleIterator with other iterators, e.g.
with InfiniteIterator.
MultipleIterator could just compute key by imploding keys from all attached
iterators using user specified separator. I've tried this localy and worked
perfectly.
If that's the way to go, I'll be happy to help with patch.
Test script:
---------------
$multiIter = new MultipleIterator();
$multiIter->attachIterator(new ArrayIterator(array('a')));
$multiIter->attachIterator(new ArrayIterator(array('b')));
$infinityIter = new InfiniteIterator($multiIter);
foreach(new LimitIterator($infinityIter, 0, 2) as $item) {
echo $item[0] . $item[1];
}
Expected result:
----------------
I expect "abab" to be printed
Actual result:
--------------
Warning: Illegal type returned from MultipleIterator::key() in
/some/path/phptests/iterators/InfinityIterator.php on line 8
ab
Warning: Illegal type returned from MultipleIterator::key() in
/some/path/phptests/iterators/InfinityIterator.php on line 8
ab
Warning: Illegal type returned from MultipleIterator::key() in
/some/path/phptests/iterators/InfinityIterator.php on line 8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64643&edit=1
Thread (2 messages)