php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-09 04:07 UTC] danielklein at airpost dot net
Sorry! I swapped Actual and Expected results!
 [2014-09-09 07:04 UTC] datibbaw@php.net
-Assigned To: +Assigned To: datibbaw
 [2014-09-09 10:05 UTC] datibbaw@php.net
Automatic comment on behalf of datibbaw
Revision: http://git.php.net/?p=php-src.git;a=commit;h=99f0760bfba86f45af9ea011a0f017080922710a
Log: Fixed #67985 - Incorrect last used array index copied to new array after unset
 [2014-09-09 10:05 UTC] datibbaw@php.net
-Status: Assigned +Status: Closed
 [2014-09-09 11:33 UTC] datibbaw@php.net
Automatic comment on behalf of datibbaw
Revision: http://git.php.net/?p=php-src.git;a=commit;h=99f0760bfba86f45af9ea011a0f017080922710a
Log: Fixed #67985 - Incorrect last used array index copied to new array after unset
 [2014-10-07 23:13 UTC] stas@php.net
Automatic comment on behalf of datibbaw
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=99f0760bfba86f45af9ea011a0f017080922710a
Log: Fixed #67985 - Incorrect last used array index copied to new array after unset
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of datibbaw
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=99f0760bfba86f45af9ea011a0f017080922710a
Log: Fixed #67985 - Incorrect last used array index copied to new array after unset
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC