php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70053 MutlitpleIterator array-keys incompatible change in PHP 7
Submitted: 2015-07-12 15:14 UTC Modified: 2015-07-12 16:29 UTC
From: hanskrentel at yahoo dot de Assigned: datibbaw
Status: Closed Package: SPL related
PHP Version: 7.0.0beta1 OS: Linux/Docker/Travis
Private report: No CVE-ID:
 [2015-07-12 15:14 UTC] 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
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-12 15:26 UTC] 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 16:29 UTC] datibbaw@php.net
-Assigned To: +Assigned To: datibbaw
 [2015-07-12 16:34 UTC] datibbaw@php.net
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
 [2015-07-12 16:34 UTC] datibbaw@php.net
-Status: Assigned +Status: Closed
 [2015-07-13 05:36 UTC] hanskrentel at yahoo dot de
Can confirm my tests went green already yesterday evening. Thanks for the very quick fix!
 [2015-07-21 14:21 UTC] ab@php.net
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
 [2016-07-20 11:37 UTC] davey@php.net
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
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Apr 28 08:01:50 2017 UTC