Bug #67985 [Opn]: Incorrect last used array index copied to new array after unset
| From: | danielklein at airpost dot net | Date: | Tue, 09 Sep 2014 04:07:15 +0000 |
| Subject: | Bug #67985 [Opn]: Incorrect last used array index copied to new array after unset | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187463@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67985&edit=1
ID: 67985
User updated by: danielklein at airpost dot net
Reported by: danielklein at airpost dot net
Summary: Incorrect last used array index copied to new array
after unset
Status: Open
Type: Bug
Package: Arrays related
PHP Version: 5.5.16
Block user comment: N
Private report: N
New Comment:
Sorry! I swapped Actual and Expected results!
Previous Comments:
------------------------------------------------------------------------
[2014-09-09 04:05:44] danielklein at airpost dot net
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 this bug report at https://bugs.php.net/bug.php?id=67985&edit=1