Bug #67985 [Asn->Csd]: Incorrect last used array index copied to new array after unset

From: Date: Tue, 09 Sep 2014 10:05:14 +0000
Subject: Bug #67985 [Asn->Csd]: 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-187473@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 Updated by: datibbaw@php.net Reported by: danielklein at airpost dot net Summary: Incorrect last used array index copied to new array after unset -Status: Assigned +Status: Closed Type: Bug Package: Arrays related PHP Version: 5.5.16 Assigned To: datibbaw Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2014-09-09 04:07:15] danielklein at airpost dot net Sorry! I swapped Actual and Expected results! ------------------------------------------------------------------------ [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

« previous php.bugs (#187473) next »