Bug #70053 [NEW]: MutlitpleIterator array-keys incompatible change in PHP 7
| From: | hanskrentel at yahoo dot de | Date: | Sun, 12 Jul 2015 15:14:48 +0000 |
| Subject: | Bug #70053 [NEW]: MutlitpleIterator array-keys incompatible change in PHP 7 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-194353@lists.php.net to get a copy of this message | ||
From: hanskrentel at yahoo dot de
Operating system: Linux/Docker/Travis
PHP version: 7.0.0beta1
Package: SPL related
Bug Type: Bug
Bug description:MutlitpleIterator array-keys incompatible change in PHP 7
Description:
------------
SPL's MultipleIterator allows to iterate over multiple arrays at once.
It does so by providing an array for current() and key() having
(normally) one field for each of the inner iterators.
When attaching an iterator, an optional integer or string value can be
provided to specify the array-key for later use.
In PHP prior 7 attaching two iterators with the two keys string(1) "2"
and int(2) (or vice-versa) made MultipleIterator current() and key()
return an array with *one* entry taking the key as integer value
(int(2)) and the value of the later inner-iterator. This is known and
common PHP behaviour to normalize strings to integers if possible to
represent integer array keys.
In PHP 7 there is a flaw with this, as the array now contains *two*
entries, both string(1) "2" and int(2):
Test script:
---------------
<?php
echo "-- Two empty iterators attached with infos that are different but
same array key --\n";
$mit = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC);
$mit ->attachIterator(new EmptyIterator(), "2");
$mit ->attachIterator(new EmptyIterator(), 2);
var_dump($mit->countIterators());
$mit->rewind();
var_dump($mit->current());
Expected result:
----------------
-- Two empty iterators attached with infos that are different but same
array key --
int(2)
array(1) {
[2]=>
NULL
}
Actual result:
--------------
-- Two empty iterators attached with infos that are different but same
array key --
int(2)
array(2) {
["2"]=>
NULL
[2]=>
NULL
}
--
Edit bug report at https://bugs.php.net/bug.php?id=70053&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70053&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70053&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70053&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70053&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70053&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70053&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70053&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70053&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70053&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70053&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70053&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70053&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70053&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70053&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70053&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70053&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70053&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70053&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70053&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70053&r=mysqlcfg