Bug #68148 [Opn->Csd]: $this is null inside include

From: Date: Sun, 05 Oct 2014 21:44:10 +0000
Subject: Bug #68148 [Opn->Csd]: $this is null inside include
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187868@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68148&edit=1 ID: 68148 Updated by: nikic@php.net Reported by: pegasus at vaultwiki dot org Summary: $this is null inside include -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Centos 6 64-bit PHP Version: master-Git-2014-10-03 (Git) -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Fixed in https://github.com/php/php-src/commit/58f389772f19ef604ad151407c7f878fadea6c5f, thanks for the report :) Previous Comments: ------------------------------------------------------------------------ [2014-10-04 05:06:11] pegasus at vaultwiki dot org Okay, yes hello.php does output 'hi' as expected, but the content is changed to ### var_dump($this); ### It outputs NULL, which is not expected, especially since var_dump($this->hello) results in string(2) "hi". Now, to get hello.php to stop outputting 'hi' altogether, my hello.php is more complicated (and closer to the format of the real code that isn't working): #### if (!function_exists('test_fn')) { function test_fn(&$obj) { echo $obj->hello; } class NestedTest { public function doubleTest($obj) { echo $obj->hello; } } } test_fn($this); // outputs nothing, expected 'hi' $o2 = new NestedTest(); $o2->doubleTest($this); // also outputs nothing, expected 'hi' #### ------------------------------------------------------------------------ [2014-10-03 20:52:41] nikic@php.net I can't reproduce this (with neither eval nor require). ------------------------------------------------------------------------ [2014-10-03 20:25:43] pegasus at vaultwiki dot org updated title ------------------------------------------------------------------------ [2014-10-03 20:24:58] pegasus at vaultwiki dot org It has nothing to do with the eval, and has to do with $this not being available from an included script. Create second file called hello.php: #### <php? echo $this->hello; #### Use this test case from another file: #### class Test { public $hello = 'hi'; public function testNow() { require('hello.php'); } } $o = new Test(); $o->testNow(); #### ------------------------------------------------------------------------ [2014-10-03 20:15:30] pegasus at vaultwiki dot org Okay, done some more testing, and I simplified the case too much here. The test I provided works, but the full case does not (works in 5.6.0). I will have to reinvestigate. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=68148 -- Edit this bug report at https://bugs.php.net/bug.php?id=68148&edit=1

« previous php.bugs (#187868) next »