Edit report at http://bugs.php.net/bug.php?id=54944&edit=1
ID: 54944 Updated by: [email protected] Reported by: dtrenz at gmail dot com Summary: Assignment operator assigns by reference on arrays containing objects. -Status: Open +Status: Bogus Type: Bug Package: *General Issues Operating System: Mac OSX (Snow Leopard) PHP Version: 5.3.6 Block user comment: N Private report: N 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 Objects are reference types. For making an copy an explicit clone is needed. PHP internal functions won't do that. Previous Comments: ------------------------------------------------------------------------ [2011-05-27 19:56:56] dtrenz at gmail dot com Description: ------------ When assigning one array to another array that contains a collection of objects, the assignment is by reference. Test script: --------------- <?php $obj = (object) null; $obj->name = 'Joe'; $arrA = array($obj); $arrB = array(); $arrB = $arrA; $arrB[0]->name = 'Mary'; print_r($arrA); print_r($arrB); Expected result: ---------------- Array ( [0] => stdClass Object ( [name] => Joe ) ) Array ( [0] => stdClass Object ( [name] => Mary ) ) Actual result: -------------- Array ( [0] => stdClass Object ( [name] => Mary ) ) Array ( [0] => stdClass Object ( [name] => Mary ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54944&edit=1
