|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-01-06 20:23 UTC] jani@php.net
[2010-01-07 09:04 UTC] israel at toxinworks dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 02:00:01 2025 UTC |
Description: ------------ PHP 5 does not copy object from array[ndx] to a new array entry, instead it seems to pass a reference to the original. Reproduce code: --------------- function fetchData() { // return array of objects } $arr = fetchData(); $newNdx = count($arr); $arr[$newNdx] = $arr[0]; // create copy of first object $arr[$newNdx]->description = 'Change description'; Expected result: ---------------- The result is that $arr[0]->description will also have changed when we modified $arr[$newNdx]->description, therefor not copying, but more like creating a reference to the original. This happens only in PHP 5, not 4.