#14990 [Csd]: array_merge_recursive modifies inputted value

From: Date: Tue, 12 Nov 2002 10:39:09 +0000
Subject: #14990 [Csd]: array_merge_recursive modifies inputted value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-24675@lists.php.net to get a copy of this message
ID: 14990 Updated by: philip@php.net Reported By: philip@cornado.com Status: Closed Bug Type: Arrays related Operating System: n/a PHP Version: 4.1.1 New Comment: It's fixed in CVS and PHP 4.3.0-dev is showing correct bahavior. Will add documention shortly. Previous Comments: ------------------------------------------------------------------------ [2002-11-11 22:22:58] mailfrom-bugs.php.net@kopka.net This annoying Bug is still inside php-4.2.3 ------------------------------------------------------------------------ [2002-04-24 11:02:25] andrei@php.net This bug has been fixed in CVS. ------------------------------------------------------------------------ [2002-01-11 04:32:53] philip@cornado.com With 3+ parameters, only the first parameter is left untouched. All others are affected, as demonstrated above with $b. ------------------------------------------------------------------------ [2002-01-11 04:02:21] philip@cornado.com In Summary: -------------- array_merge_recursive() modifies the array entered as the second parameter if the merged arrays have at least one identical stringed key. It will affect all such duplicate keys, and modify the second parameter's array as demonstrated below. Example: -------------- <?php $a = array(2 => '2 a', 'foo' => 'foo a','bar' => 'bar a'); $b = array(2 => '2 b', 'foo' => 'foo b','bar' => 'bar b'); $c['recursive'] = array_merge_recursive($a,$b); $c['a'] = $a; $c['b'] = $b; print_r($c); ?> Example output: --------------- Array ( [recursive] => Array ( [0] => 2 a [foo] => Array ( [0] => foo a [1] => foo b ) [bar] => Array ( [0] => bar a [1] => bar b ) [1] => 2 b ) [a] => Array ( [2] => 2 a [foo] => foo a [bar] => bar a ) [b] => Array ( [2] => 2 b [foo] => Array ( [0] => foo b ) [bar] => Array ( [0] => bar b ) ) ) Notes: ---------------- Notice how in $b, keys 'foo' and 'bar' are now arrays when initially they were not. This behavior exists with all such duplicate stringed keys. array_merge_recursive() should not directly affect inputted values. This seems related to bug #14128. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=14990&edit=1

« previous php.bugs (#24675) next »