Bug #52428 [Opn->Bgs]: $this isn't immutable
| From: | johannes@php.net | Date: | Sun, 25 Jul 2010 16:39:18 +0000 |
| Subject: | Bug #52428 [Opn->Bgs]: $this isn't immutable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152763@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52428&edit=1
ID: 52428
Updated by: johannes@php.net
Reported by: tyra3l at gmail dot com
Summary: $this isn't immutable
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: all
PHP Version: 5.3.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
We prevent from mistakes, we don't prevent people from hurting them
purposely. If you want you can shoot yourself in your head.
Previous Comments:
------------------------------------------------------------------------
[2010-07-24 11:36:17] tyra3l at gmail dot com
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 this bug report at http://bugs.php.net/bug.php?id=52428&edit=1