|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-22 13:36 UTC] johannes@php.net
-Package: Feature/Change Request
+Package: *General Issues
[2010-12-22 13:36 UTC] johannes@php.net
[2010-12-22 15:04 UTC] johannes@php.net
-Status: Open
+Status: Bogus
[2010-12-22 15:04 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 22:00:02 2025 UTC |
Description: ------------ Usually $this cannot be set. But by creating a reference to $this it can. In the example the reference is created by the =& operator. The problem is also valid when passing $this to a function by reference. I think an error should be generated because both $this = 1 and $this =& $x do generate an error. Reproduce code: --------------- class testclass { function foo() { var_dump($this); // object(testclass)#1 (0) { } $this->bar(); var_dump($this); // object(testclass)#1 (0) { } } function bar() { $a =& $this; $a = 1; var_dump($this); // int(1) } } $b = new testclass; $b->foo(); Expected result: ---------------- Fatal error: Cannot re-assign $this in eval()'d code on line 12 Actual result: -------------- object(testclass)#1 (0) { } int(1) object(testclass)#1 (0) { }