From:
Operating system: all
PHP version: 5.3.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:$this isn't immutable
Description:
------------
As some closed bug-reports and the "PHP Fatal error: Cannot re-assign
$this"
states, the $this should be read-only/inmutable in PHP5.
but with some tricks(variable variables mostly), you can walk-around this
constraint.
See the Test script.
I don't know the importance of this restriction, and with reflection you
can shoot
you in the leg anyway, so maybe this can be left as is.
Test script:
---------------
<?php
error_reporting(E_ALL);
$var = new StdClass();
$var->foo = 'bar';
//$this = $var; // PHP Fatal error: Cannot re-assign $this
$GLOBALS['this'] = $var;
var_dump($this);
$var->foo = 'baz';
$foo = 'this';
$$foo = $var;
var_dump($this);
foo($this);
function foo($this){
//global $this; // PHP Fatal error: Cannot re-assign $this
// $this = $GLOBALS['var']; // PHP Fatal error: Cannot re-assign $this
var_dump($this);
$GLOBALS['this']->foo = 'baw';
$$GLOBALS['foo'] = $GLOBALS['this'];
var_dump($this);
}
Expected result:
----------------
PHP Fatal error: Cannot re-assign $this
for every attempt to overwrite $this
Actual result:
--------------
you can set $this in the global scope through $GLOBALS, with argument in
functions, and with variable variables in everywhere.
--
Edit bug report at http://bugs.php.net/bug.php?id=52428&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52428&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52428&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=52428&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52428&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=52428&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52428&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=52428&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=52428&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=52428&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=52428&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=52428&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=52428&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=52428&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52428&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52428&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52428&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=52428&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=52428&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=52428&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=52428&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=52428&r=mysqlcfg