#43559 [Opn]: array_merge_recursive() doesn't behave as expected with duplicate NULL values
| From: | andrei@php.net | Date: | Wed, 23 Jan 2008 00:35:55 +0000 |
| Subject: | #43559 [Opn]: 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-121464@lists.php.net to get a copy of this message | ||
ID: 43559
Updated by: andrei@php.net
Reported By: kraghuba at in dot ibm dot com
Status: Open
Bug Type: Arrays related
Operating System: Linux, windows
PHP Version: 5.2CVS-2007-12-11 (snap)
New Comment:
Looks fine to me.
Previous Comments:
------------------------------------------------------------------------
[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