Bug #64741 [Nab]: Various ways to reassign this

2013-05-01 Thread php dot bugs at daverandom dot com
Edit report at https://bugs.php.net/bug.php?id=64741&edit=1

 ID: 64741
 User updated by:    php dot bugs at daverandom dot com
 Reported by:    php dot bugs at daverandom dot com
 Summary:Various ways to reassign this
 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:

I accept that the bulk of the examples below are difficult/impossible to 
prevent 
with the static analysis that happens at compile time, given the range of 
dynamic ways to do this that makes PHP a great language. I too would not like 
to 
see PEBKAC prevention affecting performance.

However, I think there is one example above that warrants further inspection: 
unset($this) actually causes a segfault (this can be seen here: 
http://codepad.viper-7.com/NX7v1q) and should be detectable at compile time 
fairly easily/inexpensively I would have thought, although I'm no expert on the 
PHP src.


Previous Comments:

[2013-04-30 11:52:38] johan...@php.net

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.


[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:
---
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


[PHP-BUG] Bug #64741 [NEW]: Various ways to reassign this

2013-04-30 Thread php dot bugs at daverandom dot com
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:
---
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