Incorrect last used array index copied to new array after unset

Bug #67985 Incorrect last used array index copied to new array after unset
Submitted: 2014-09-09 04:05 UTC Modified: 2014-09-09 07:04 UTC
From: danielklein at airpost dot net Assigned: datibbaw (profile)
Status: Closed Package: Arrays related
PHP Version: 5.5.16 OS:
Private report: No CVE-ID: None

 [2014-09-09 04:05 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2014-09-09 04:07 UTC] danielklein at airpost dot net

Sorry! I swapped Actual and Expected results!