From: php dot bugs at daverandom dot com
Operating system: Any
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Various ways to reassign this
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 bug report at https://bugs.php.net/bug.php?id=64741&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=64741&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=64741&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=64741&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64741&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64741&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64741&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64741&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64741&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64741&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64741&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=64741&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=64741&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64741&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64741&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64741&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64741&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64741&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64741&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64741&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64741&r=mysqlcfg