|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-04-30 11:52 UTC] johannes@php.net
[2013-04-30 11:52 UTC] johannes@php.net
-Status: Open
+Status: Not a bug
[2013-05-01 10:01 UTC] php dot bugs at daverandom dot com
[2013-05-03 15:28 UTC] nikic@php.net
[2013-05-03 15:28 UTC] nikic@php.net
-Status: Not a bug
+Status: Feedback
[2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 12:00:02 2025 UTC |
Description: ------------ The engine prevents userland code from directly reassigning $this with a compile time error, but it does not prevent a number of other mechanisms. The following are all possible: unset($this); // ... public function test() { ${'th'.'is'} = 'foo'; } // ... public function test() { $foo = 'this'; $$foo = 'foo'; } // ... function ref(&$arg) { $arg = 'foo'; } public function test() { ref($this); } Test script: --------------- <?php function ref(&$arg) { $arg = 'foo'; } class ThisReassignments { public function test1() { var_dump($this); ${'th'.'is'} = 'foo'; var_dump($this); } public function test2() { var_dump($this); $foo = 'this'; $$foo = 'foo';; var_dump($this); } public function test3() { var_dump($this); ref($this); var_dump($this); } } (new ThisReassignments)->test1(); (new ThisReassignments)->test2(); (new ThisReassignments)->test3(); // NB: unset() causes a segmentation fault and doesn't *really* work, but it should emit a meaningful error Expected result: ---------------- Fatal error with a meaningful error message in all cases Actual result: -------------- object(ThisReassignments)#1 (0) { } string(3) "foo" object(ThisReassignments)#1 (0) { } string(3) "foo" object(ThisReassignments)#1 (0) { } string(3) "foo"