#47080 [Opn->Bgs]: Type of variable changes after it has been returned by reference
| From: | tony2001@php.net | Date: | Tue, 10 Feb 2009 10:57:14 +0000 |
| Subject: | #47080 [Opn->Bgs]: Type of variable changes after it has been returned by reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-133667@lists.php.net to get a copy of this message | ||
ID: 47080
Updated by: tony2001@php.net
Reported By: foddex at foddex dot net
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux Fedora 9
PHP Version: 5.2.8
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
"A reference" means several variables share the same value.
http://www.php.net/manual/en/language.references.whatare.php
Previous Comments:
------------------------------------------------------------------------
[2009-01-12 14:20:19] foddex at foddex dot net
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)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47080&edit=1