From: Operating system: Debian Squeeze, 64-bit PHP version: 5.3.10 Package: Arrays related Bug Type: Bug Bug description:array_merge() does only merge references of objects
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 bug report at https://bugs.php.net/bug.php?id=61299&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61299&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61299&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61299&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61299&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61299&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61299&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61299&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61299&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61299&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61299&r=support Expected behavior: https://bugs.php.net/fix.php?id=61299&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61299&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61299&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61299&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61299&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61299&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61299&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61299&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61299&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61299&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61299&r=mysqlcfg