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

From: Date: Sun, 02 Mar 2014 09:03:02 +0000
Subject: Bug #66809 [NEW]: Inconsistence in using $this variable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184496@lists.php.net to get a copy of this message
From:             o dot pikozh at gmail dot com
Operating system: 
PHP version:      5.6.0alpha2
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Inconsistence in using $this variable

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 bug report at https://bugs.php.net/bug.php?id=66809&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66809&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66809&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66809&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66809&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66809&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66809&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66809&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66809&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66809&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66809&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66809&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66809&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66809&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66809&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66809&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66809&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66809&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66809&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66809&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66809&r=mysqlcfg



Thread (10 messages)

« previous php.bugs (#184496) next »