|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-07-12 15:26 UTC] hanskrentel at yahoo dot de
[2015-07-12 16:29 UTC] datibbaw@php.net
-Assigned To:
+Assigned To: datibbaw
[2015-07-12 16:34 UTC] datibbaw@php.net
[2015-07-12 16:34 UTC] datibbaw@php.net
-Status: Assigned
+Status: Closed
[2015-07-13 05:36 UTC] hanskrentel at yahoo dot de
[2015-07-21 14:21 UTC] ab@php.net
[2016-07-20 11:37 UTC] davey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
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 }