Bug #66809 [Opn->Dup]: Inconsistence in using $this variable
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
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.6.0alpha2
Block user comment: N
Private report: N
New Comment:
closing at as duplicate
Previous Comments:
------------------------------------------------------------------------
[2014-04-13 20:42:08] tyrael@php.net
for the reference, I made a similar report a couple of years back:
http://bugs.php.net/52428
------------------------------------------------------------------------
[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
Thread (10 messages)