#34834 [Opn->Bgs]: array_merge_recursive merges objects with arrays
| From: | sniper@php.net | Date: | Tue, 01 Nov 2005 10:25:27 +0000 |
| Subject: | #34834 [Opn->Bgs]: array_merge_recursive merges objects with arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87313@lists.php.net to get a copy of this message | ||
ID: 34834
Updated by: sniper@php.net
Reported By: tomas_matousek at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: WinXP
PHP Version: 5.1.0RC1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2005-10-11 23:35:21] tomas_matousek at hotmail dot com
Description:
------------
Although one cannot pass obejects to array_merge_recursive() function,
it looks like it doesn't ignore objects at all.
If objects are contained in the array it merges them as if they were
arrays of fields. I think it is not good to treat objects in this way
when other array functions doesn't do so (e.g. array_walk_recursive
doesn't step to fields of objects).
Reproduce code:
---------------
class A
{
var $field = array(1);
}
$a = new A;
$x = array("a" => $a);
$y = array("a" => array("field" => array(2)));
var_dump(array_merge_recursive($x,$y));
Expected result:
----------------
array(1) {
["a"]=>
array(2) {
[0]=>
object(A)#1 (1) {
["field"]=>
array(1) {
[0]=>
int(1)
}
}
["field"]=>
array(1) {
[0]=>
int(2)
}
}
}
Actual result:
--------------
array(1) {
["a"]=>
array(1) {
["field"]=>
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34834&edit=1