Bug #67169 [NEW]: array_splice all elements, then []= gives wrong index
| From: | gabriel at figdice dot org | Date: | Thu, 01 May 2014 14:38:39 +0000 |
| Subject: | Bug #67169 [NEW]: array_splice all elements, then []= gives wrong index | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185550@lists.php.net to get a copy of this message | ||
From: gabriel at figdice dot org
Operating system: Debian Wheezy
PHP version: 5.6.0beta1
Package: Arrays related
Bug Type: Bug
Bug description:array_splice all elements, then []= gives wrong index
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
)
*/
--
Edit bug report at https://bugs.php.net/bug.php?id=67169&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67169&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67169&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67169&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67169&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67169&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67169&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67169&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67169&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67169&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67169&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67169&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67169&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67169&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67169&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67169&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67169&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67169&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67169&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67169&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67169&r=mysqlcfg