Req #50806 [Asn->Wfx]: $this can be assigned using variable casting
| From: | dmitry@php.net | Date: | Tue, 20 Apr 2010 14:18:02 +0000 |
| Subject: | Req #50806 [Asn->Wfx]: $this can be assigned using variable casting | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149729@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=50806&edit=1
ID: 50806
Updated by: dmitry@php.net
Reported by: kominbhai at gmail dot com
Summary: $this can be assigned using variable casting
-Status: Assigned
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Windows Vista
PHP Version: 5.*, 6, 7, 8, 9..
Assigned To: dmitry
New Comment:
It's possible to do it even without dynamic tricks.
<?php
class Foo {
function bar() {
$x = &$this;
$x = null;
var_dump($this);
}
}
$x = new Foo();
$x->bar();
?>
I would say I don't like to fix all these issues, because the fixes
would slowdown absolutely legal PHP code.
Previous Comments:
------------------------------------------------------------------------
[2010-01-24 04:56:45] kalle@php.net
There are several other ways to also re-assign $this, e.g.:
class Test {
public function __construct() {
var_dump($this);
/* Quirk comes in here by using the concation operator */
/* ${'this'} is not possible and results in an E_ERROR */
${'t' . 'his'} = 'Hello';
var_dump($this);
}
}
If any whether this should be fixed within the Engine, then Dmitry would
know so I'm re-assigning it to him for him to decide. As for a
documentation issue, I really don't belive we should document such
quirks in the official documentation else people will rely on such buggy
"features".
------------------------------------------------------------------------
[2010-01-20 15:48:54] kominbhai at gmail dot com
Description:
------------
$this can be assigned using variable casting
Reproduce code:
---------------
<?php
$a="this";
$$a="abc";
echo $this; //works when it should not be
?>
Expected result:
----------------
Error: $this cannot be re-assigned
Actual result:
--------------
echoes abc
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=50806&edit=1