Edit report at https://bugs.php.net/bug.php?id=61299&edit=1
ID: 61299 Updated by: cataphr...@php.net Reported by: simon dot sattes at gmail dot com Summary: array_merge() does only merge references of objects -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Debian Squeeze, 64-bit PHP Version: 5.3.10 Block user comment: N Private report: N New Comment: No bug here. Object variables have an extra level of indirection (they're object references). This is the general behavior of the language and doesn't require a special mention in array_merge. Previous Comments: ------------------------------------------------------------------------ [2012-03-06 10:58:58] simon dot sattes at gmail dot com Description: ------------ I'm not sure, if this is a bug or a desired behaviour that is not mentioned in the docs. When merging an array with itself with array_merge() then modifiying one array element afterwards does also affect all other elements. If it's intentional, then it should be mentionend in the documentation. Test script: --------------- <?php $items = array(); $items[] = (object) array( 'year' => 2012, 'desc' => 'something happens' ); $many = array_merge($items, $items); print_r($many); $many[0]->year = 2040; print_r($many); // changes also year of $many[1] Expected result: ---------------- $many[0]->year should be 2040 $many[1]->year should be 2012 Actual result: -------------- $many[0]->year is 2040 $many[1]->year is 2040 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61299&edit=1