#43559 [Opn->Csd]: array_merge_recursive() doesn't behave as expected with duplicate NULL values

From: Date: Wed, 23 Jan 2008 12:06:59 +0000
Subject: #43559 [Opn->Csd]: array_merge_recursive() doesn't behave as expected with duplicate NULL values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121481@lists.php.net to get a copy of this message
ID: 43559 Updated by: tony2001@php.net Reported By: kraghuba at in dot ibm dot com -Status: Open +Status: Closed Bug Type: Arrays related Operating System: Linux, windows PHP Version: 5.2CVS-2007-12-11 (snap) New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2008-01-23 09:59:41] felipe@php.net The .phpt also fixed: http://ecl.zoone.com.br/etc/patches/array_merge_recursive_variation5.patch ------------------------------------------------------------------------ [2008-01-23 00:35:52] andrei@php.net Looks fine to me. ------------------------------------------------------------------------ [2008-01-17 21:35:13] felipe@php.net Simple fix: http://ecl.zoone.com.br/etc/patches/bug43559.patch ------------------------------------------------------------------------ [2007-12-11 05:35:05] kraghuba at in dot ibm dot com Description: ------------ When two arrays having common key and value are passed as argument to array_merge_recursive(), the function behaves in an unexpected way for NULL values. It outputs an empty array instead of an array having two elements, both being NULL. Whereas, the function behaves in an expected way with values other than NULL. This behavior can be observed in the testcase array_merge_recursive_variation9.phpt. This behavior is observed in PHP5.3 and PHP6 as well. I tried creating an array with two null values and it works: <?php $a = array(NULL, NULL); var_dump($a); ?> output: array(2) { [0]=> NULL [1]=> NULL } Reproduce code: --------------- <?php $a1 = array( 'b' => 'string' ); $a2 = array( 'b' => 'string' ); $a3 = array( 'b' => NULL ); $a4 = array( 'b' => NULL ); var_dump( array_merge_recursive($a1, $a2) ); // expected output var_dump( array_merge_recursive($a3, $a4) ); // unexpecteed output ?> Expected result: ---------------- array(1) { ["b"]=> array(2) { [0]=> string(6) "string" [1]=> string(6) "string" } } array(1) { ["b"]=> array(2) { [0]=> NULL [1]=> NULL } } Actual result: -------------- array(1) { ["b"]=> array(2) { [0]=> string(6) "string" [1]=> string(6) "string" } } array(1) { ["b"]=> array(0) { } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43559&edit=1

« previous php.bugs (#121481) next »