Bug #66809 [Dup]: Inconsistence in using $this variable
| From: | o dot pikozh at gmail dot com | Date: | Tue, 03 Jun 2014 11:24:13 +0000 |
| Subject: | Bug #66809 [Dup]: Inconsistence in using $this variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186026@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
User updated by: o dot pikozh at gmail dot com
Reported by: o dot pikozh at gmail dot com
Summary: Inconsistence in using $this variable
Status: Duplicate
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.6.0alpha2
Block user comment: N
Private report: N
New Comment:
This is not an exact duplicate.
That report was in fact about that '$GLOBALS["this"]' can be assigned using
'$GLOBALS["this"] = ...', but cannot be assigned using 'global $this'
or '$this = ...'.
This report is in fact about that if you set parameter name to 'this', you somewhy cannot
read its members (although it is not forbidden to set parameter name per se, and to read or copy
parameter value itself).
Previous Comments:
------------------------------------------------------------------------
[2014-06-03 07:27:59] tyrael@php.net
closing at as duplicate
------------------------------------------------------------------------
[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