|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-14 19:12 UTC] code at dumb dot ro
[2011-01-23 21:14 UTC] jani@php.net
-Package: Feature/Change Request
+Package: Class/Object related
-Operating System: all
+Operating System: *
[2014-04-16 23:31 UTC] levim@php.net
-Status: Open
+Status: Feedback
-Operating System: *
+Operating System: Irrelevant
[2014-04-16 23:31 UTC] levim@php.net
[2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 19:00:01 2025 UTC |
Description: ------------ When you pass an array of objects to a function (not by reference) and you modfiy one of the objects in the array, the main array (the referenced objects) will be modified. This wasn't a problem until objects got passed by reference by default. Reproduce code: --------------- $class A { } $a = new A(); $a->x = 10; $arr = array($a); function foo($arr) { $arr[0]->x = 1; } foo($arr); print_r($arr); Expected result: ---------------- the expected result would be 10 Actual result: -------------- since the array is internally using references for the stored objects the result will be 1. to fix this I wrote a function that clones the array properly and I'm calling the function like this: foo(array_clone($arr));