Bug #68282 [Opn->Nab]: Array resulting from array_diff starts at wrong index

From: Date: Wed, 22 Oct 2014 13:07:41 +0000
Subject: Bug #68282 [Opn->Nab]: Array resulting from array_diff starts at wrong index
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188260@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68282&edit=1 ID: 68282 Updated by: bwoebi@php.net Reported by: david dot lin dot au at gmail dot com Summary: Array resulting from array_diff starts at wrong index -Status: Open +Status: Not a bug Type: Bug Package: Arrays related PHP Version: 5.4.34 Block user comment: N Private report: N New Comment: What had been changed by http://git.php.net/?p=php-src.git;a=commitdiff;h=99f0760bfba86f45af9ea011a0f017080922710a is that next array keys to use aren't reset anymore if an array is copied. (That it wasn't copied *was* a bug) Also, array_diff just copies the next key to use from the first array. So, the next key to use in $a1 was 4, in $a2 then too. Which is copied also to $a3; that's why you get key 4 when you try to $a3[] = "value";. Previous Comments: ------------------------------------------------------------------------ [2014-10-22 06:15:17] david dot lin dot au at gmail dot com Description: ------------ Adding elements to array resulting from array_diff is allocated with wrong numeric index key. Test script: --------------- <?php $a1 = array( 'one', 'two', 'three', 'four' ); $a2 = array_diff( $a1, array( 'one', 'two', 'three', 'four' ) ); $a3 = $a2; $a3[] = 'five'; print_r($a3); Expected result: ---------------- Array ( [0] => five ) Actual result: -------------- Output for PHP 4.3.0 - 5.4.32, 5.5.0 - 5.5.16, 5.6.0, php7@20140507 - 20140521, php7@20140801, hhvm-3.0.1 - 3.3.0 : Array ( [0] => five ) Output for PHP 5.4.34, 5.5.18, 5.6.1 - 5.6.2, php7@20140701, php7@20140901 - 20141001 : Array ( [4] => five ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68282&edit=1

« previous php.bugs (#188260) next »