Edit report at https://bugs.php.net/bug.php?id=64741&edit=1
ID: 64741 User updated by: php dot bugs at daverandom dot com Reported by: php dot bugs at daverandom dot com Summary: Various ways to reassign this Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I accept that the bulk of the examples below are difficult/impossible to prevent with the static analysis that happens at compile time, given the range of dynamic ways to do this that makes PHP a great language. I too would not like to see PEBKAC prevention affecting performance. However, I think there is one example above that warrants further inspection: unset($this) actually causes a segfault (this can be seen here: http://codepad.viper-7.com/NX7v1q) and should be detectable at compile time fairly easily/inexpensively I would have thought, although I'm no expert on the PHP src. Previous Comments: ------------------------------------------------------------------------ [2013-04-30 11:52:38] johan...@php.net 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 we prevent from mistakes, we don't prevent people from shooting in their feed, especially as such checks would slow down *all* variable access. ------------------------------------------------------------------------ [2013-04-30 11:42:15] php dot bugs at daverandom dot com 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64741&edit=1