|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-06-09 02:11 UTC] scottmac@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 15:00:01 2025 UTC |
Description: ------------ When you pass the $this pointer by reference and change data for the object it points to, that data is not correctly updated. Reproduce code: --------------- function changeAddress(&$oldThing) { $oldThing = new Thing(); } class Thing { var $data; public function updateData($newData) { ThingChanger::changeData($this,$newData); var_dump($this); var_dump($this->data); } } class ThingChanger { public static function changeData(&$thingToChange,$newData) { changeAddress($thingToChange); $thingToChange->data = $newData; } } $thing = new Thing(); $thing->data = "foo"; $thing->updateData("bar"); Expected result: ---------------- object(Thing)#2 (1) { ["data"]=> string(3) "bar" } string(3) "bar" Actual result: -------------- object(Thing)#2 (1) { ["data"]=> string(3) "bar" } string(3) "foo"