Bug #64741 [Opn->Nab]: Various ways to reassign this
Edit report at https://bugs.php.net/bug.php?id=64741&edit=1
ID: 64741
Updated by: johannes@php.net
Reported by: php dot bugs at daverandom dot com
Summary: Various ways to reassign this
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
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 shooting in their feed, especially as
such checks would slow down *all* variable access.
Previous Comments:
------------------------------------------------------------------------
[2013-04-30 11:42:15] php dot bugs at daverandom dot com
Description:
------------
The engine prevents userland code from directly reassigning $this with a compile
time error, but it does not prevent a number of other mechanisms. The following
are all possible:
unset($this);
// ...
public function test()
{
${'th'.'is'} = 'foo';
}
// ...
public function test()
{
$foo = 'this';
$$foo = 'foo';
}
// ...
function ref(&$arg)
{
$arg = 'foo';
}
public function test()
{
ref($this);
}
Test script:
---------------
<?php
function ref(&$arg)
{
$arg = 'foo';
}
class ThisReassignments
{
public function test1() { var_dump($this); ${'th'.'is'} =
'foo'; var_dump($this); }
public function test2() { var_dump($this); $foo = 'this'; $$foo =
'foo';; var_dump($this); }
public function test3() { var_dump($this); ref($this); var_dump($this); }
}
(new ThisReassignments)->test1();
(new ThisReassignments)->test2();
(new ThisReassignments)->test3();
// NB: unset() causes a segmentation fault and doesn't *really* work, but it should emit a
meaningful error
Expected result:
----------------
Fatal error with a meaningful error message in all cases
Actual result:
--------------
object(ThisReassignments)#1 (0) {
}
string(3) "foo"
object(ThisReassignments)#1 (0) {
}
string(3) "foo"
object(ThisReassignments)#1 (0) {
}
string(3) "foo"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64741&edit=1
Thread (5 messages)