Bug #70053 [Asn->Csd]: MutlitpleIterator array-keys incompatible change in PHP 7
| From: | datibbaw@php.net | Date: | Sun, 12 Jul 2015 16:34:54 +0000 |
| Subject: | Bug #70053 [Asn->Csd]: MutlitpleIterator array-keys incompatible change in PHP 7 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194355@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70053&edit=1
ID: 70053
Updated by: datibbaw@php.net
Reported by: hanskrentel at yahoo dot de
Summary: MutlitpleIterator array-keys incompatible change in
PHP 7
-Status: Assigned
+Status: Closed
Type: Bug
Package: SPL related
Operating System: Linux/Docker/Travis
PHP Version: 7.0.0beta1
Assigned To: datibbaw
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of datibbaw
Revision: http://git.php.net/?p=php-src.git;a=commit;h=03d18d9a52065689d27384e95a54b7ae01e77780
Log: Fixed #70053 MutlitpleIterator array-keys incompatible change in PHP 7
Previous Comments:
------------------------------------------------------------------------
[2015-07-12 15:26:12] hanskrentel at yahoo dot de
Was unsure about the version because I experienced it on Travis, here is the example on 3v4l.org: http://3v4l.org/SCoaa
------------------------------------------------------------------------
[2015-07-12 15:14:46] hanskrentel at yahoo dot de
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 this bug report at https://bugs.php.net/bug.php?id=70053&edit=1