Bug #70053 [Com]: MutlitpleIterator array-keys incompatible change in PHP 7

From: Date: Sun, 12 Jul 2015 15:26:12 +0000
Subject: Bug #70053 [Com]: MutlitpleIterator array-keys incompatible change in PHP 7
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194354@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 Comment by: hanskrentel at yahoo dot de Reported by: hanskrentel at yahoo dot de Summary: MutlitpleIterator array-keys incompatible change in PHP 7 Status: Open Type: Bug Package: SPL related Operating System: Linux/Docker/Travis PHP Version: 7.0.0beta1 Block user comment: N Private report: N New Comment: Was unsure about the version because I experienced it on Travis, here is the example on 3v4l.org: http://3v4l.org/SCoaa Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#194354) next »