|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-02-10 10:57 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 21:00:01 2025 UTC |
Description: ------------ When a class member variable gets returned by reference, the member variable itself turns into a reference. See the URL below for more detailed information (it contains a lot of comments). The basic idea is: class A { var $foo; function &get() { return $this->foo; } } If we clone an instance of A when get() hasn't been returned yet, the value of $foo gets cloned. If we call get(), and then clone the instance of A, the cloned object references the same data as the original! This might be logical because it had become a reference, but this behavior is not documented and thus pretty unexpected, IMHO. Reproduce code: --------------- http://pastebin.be/16008 Expected result: ---------------- object(A)#1 (1) { ["foo"]=> int(42) } int(42) int(43) int(42) object(A)#1 (1) { ["foo"]=> int(43) } Actual result: -------------- object(A)#1 (1) { ["foo"]=> int(42) } int(42) int(43) int(43) object(A)#1 (1) { ["foo"]=> &int(43) }