|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-05-01 20:54 UTC] nikic@php.net
-Assigned To:
+Assigned To: nikic
[2014-05-02 10:53 UTC] nikic@php.net
[2014-05-02 10:53 UTC] nikic@php.net
-Status: Assigned
+Status: Closed
[2014-05-02 10:54 UTC] nikic@php.net
[2014-05-05 06:56 UTC] ab@php.net
[2014-05-05 07:00 UTC] ab@php.net
[2014-05-14 07:57 UTC] tyrael@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
Description: ------------ REGRESSION in beta1: the scenario worked fine until 5.6.0alpha1 incl. When splicing off all the elements of an indexed array, thus leaving the array empty, a subsequent all to the shortcut []= assignment will set the new item at a key which is not zero (unlike expected) but the previous "next index", which is what would happen should we not have spliced the array empty. For example, if you append two items in an array, then array_splice them off (from index 0, for length 2, replacing with nothing), then if later on you append a brand new element in your emptied array, it gets index 2 instead of expected 0. Test script: --------------- <?php // Bug in PHP 5.6.0-beta-1 // also failing in PHP 5.7.0-dev // When splicing off all the elements of an indexed array, // thus leaving the array empty, // a subsequent all to the shortcut []= assignment will set the new item // at a key which is not zero (unlike expected) but the previous "next index", // which is what would happen should we not have spliced the array empty. $arr = array(); $arr[] = 'something'; $arr[] = 'some more'; array_splice($arr, 0, 2); $arr[] = 'should be index zero'; print_r($arr); /* will produce: Array ( [2] => should be index zero ) */