Bug #14990: array_merge_recursive modifies inputted value

From: Date: Fri, 11 Jan 2002 09:02:22 +0000
Subject: Bug #14990: array_merge_recursive modifies inputted value
Groups: php.dev 
Request: Send a blank email to php-dev+get-76592@lists.php.net to get a copy of this message
From: philip@cornado.com Operating system: n/a PHP version: 4.1.1 PHP Bug Type: Arrays related Bug description: array_merge_recursive modifies inputted value 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 bug report at: http://bugs.php.net/?id=14990&edit=1

« previous php.dev (#76592) next »