Bug #67985 [NEW]: Incorrect last used array index copied to new array after unset
| From: | danielklein at airpost dot net | Date: | Tue, 09 Sep 2014 04:05:45 +0000 |
| Subject: | Bug #67985 [NEW]: Incorrect last used array index copied to new array after unset | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187462@lists.php.net to get a copy of this message | ||
From: danielklein at airpost dot net
Operating system:
PHP version: 5.5.16
Package: Arrays related
Bug Type: Bug
Bug description:Incorrect last used array index copied to new array after unset
Description:
------------
Unsetting the last item of an array that has a numeric key updates the
last used index of the array but the previous information is used when
copying this array. Changing unset() to array_pop() produces the
expected behaviour.
Test script:
---------------
<?php
// Output using xdebug
$ary = array('zero', 'one', 'two');
//array_pop($ary);
//array_pop($ary);
unset($ary[1]);
unset($ary[2]);
$bry = $ary;
$ary[] = 'three';
$bry[] = 'three';
var_dump($ary, $bry, $ary == $bry);
?>
Expected result:
----------------
array (size=2)
0 => string 'zero' (length=4)
1 => string 'three' (length=5)
array (size=2)
0 => string 'zero' (length=4)
3 => string 'three' (length=5)
boolean false
Actual result:
--------------
array (size=2)
0 => string 'zero' (length=4)
1 => string 'three' (length=5)
array (size=2)
0 => string 'zero' (length=4)
1 => string 'three' (length=5)
boolean true
--
Edit bug report at https://bugs.php.net/bug.php?id=67985&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67985&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67985&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67985&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67985&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67985&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67985&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67985&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67985&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67985&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67985&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67985&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67985&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67985&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67985&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67985&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67985&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67985&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67985&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67985&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67985&r=mysqlcfg