From: andre at webkr dot de
Operating system: Tested on Windows and Linux
PHP version: 5.2.5
PHP Bug Type: Feature/Change Request
Bug description: $this can be overwritten by setting a reference
Description:
------------
Usually $this cannot be set. But by creating a reference to $this it can.
In the example the reference is created by the =& operator. The problem is
also valid when passing $this to a function by reference.
I think an error should be generated because both $this = 1 and $this =&
$x do generate an error.
Reproduce code:
---------------
class testclass
{
function foo()
{
var_dump($this); // object(testclass)#1 (0) { }
$this->bar();
var_dump($this); // object(testclass)#1 (0) { }
}
function bar()
{
$a =& $this;
$a = 1;
var_dump($this); // int(1)
}
}
$b = new testclass;
$b->foo();
Expected result:
----------------
Fatal error: Cannot re-assign $this in eval()'d code on line 12
Actual result:
--------------
object(testclass)#1 (0) { }
int(1)
object(testclass)#1 (0) { }
--
Edit bug report at http://bugs.php.net/?id=44552&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44552&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44552&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44552&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44552&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44552&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44552&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44552&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44552&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44552&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44552&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44552&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44552&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44552&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44552&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44552&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44552&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44552&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44552&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44552&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44552&r=mysqlcfg