Bug #66809 [Opn]: Inconsistence in using $this variable

From: Date: Sun, 13 Apr 2014 20:42:09 +0000
Subject: Bug #66809 [Opn]: Inconsistence in using $this variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185218@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66809&edit=1 ID: 66809 Updated by: tyrael@php.net Reported by: o dot pikozh at gmail dot com Summary: Inconsistence in using $this variable Status: Open Type: Bug Package: Scripting Engine problem PHP Version: 5.6.0alpha2 Block user comment: N Private report: N New Comment: for the reference, I made a similar report a couple of years back: http://bugs.php.net/52428 Previous Comments: ------------------------------------------------------------------------ [2014-03-02 09:03:01] o dot pikozh at gmail dot com Description: ------------ It is not clearly defined if user is allowed to name his variables '$this'. (Yep, I know that '$this' variable has special meaning, however its usage in non-special meaning should be clarified: - either '$this' variable can never be used in non-special meaning; - either '$this' variable can be used in non-special meaning on Test script: --------------- //Assuming we have: class TestClass {function m() {echo 'm'};} //Case 1: function f1($this) {$this->m();} //This code compiles. //Case 2: function f2($this) {$this->m();} f2(new TestClass); //This code sais: 'PHP Fatal error: Using $this when not in object context in' //Case 3: function f3($this) {$t = $this; $t->m();} f3(new TestClass); //This code compiles and says 'm'. This is inconsistent. Either it should fail immediately after reading 'function fN($this)' saying smth like 'Fatal error: Cannot use $this as custom variable/parameter name'. Or it should work. At least, cases 2 and 3 should behave identically. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66809&edit=1

« previous php.bugs (#185218) next »