From:             mikolaj dot kopras at vexillium dot org
Operating system: Ubuntu 2.6.38-15-generic x86_64
PHP version:      5.4.14
Package:          SPL related
Bug Type:         Bug
Bug description:MultipleIterator and its not scalar keys

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 bug report at https://bugs.php.net/bug.php?id=64643&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64643&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64643&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64643&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64643&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64643&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64643&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64643&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64643&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64643&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64643&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64643&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64643&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64643&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64643&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64643&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64643&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64643&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64643&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64643&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64643&r=mysqlcfg

Reply via email to