Bug #64741 [Fbk->NoF]: Various ways to reassign this

From: Date: Tue, 15 Oct 2013 11:54:42 +0000
Subject: Bug #64741 [Fbk->NoF]: Various ways to reassign this
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182240@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64741&edit=1

 ID:               64741
 Updated by:       php-bugs@lists.php.net
 Reported by:      php dot bugs at daverandom dot com
 Summary:          Various ways to reassign this
-Status:           Feedback
+Status:           No Feedback
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Any
 PHP Version:      Irrelevant
 Private report:   N

 New Comment:

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.


Previous Comments:
------------------------------------------------------------------------
[2013-05-03 15:28:57] nikic@php.net

I am not able to reproduce the unset($this) segfault. Could you provide some more information
regarding the used PHP version and ./configure?

------------------------------------------------------------------------
[2013-05-01 10:01:22] php dot bugs at daverandom dot com

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.

------------------------------------------------------------------------
[2013-04-30 11:52:38] johannes@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:
---------------
<?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)

« previous php.bugs (#182240) next »