Bug #68148 [Com]: $this is null inside include
| From: | nikic@php.net | Date: | Fri, 03 Oct 2014 20:52:41 +0000 |
| Subject: | Bug #68148 [Com]: $this is null inside include | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187834@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
Comment by: nikic@php.net
Reported by: pegasus at vaultwiki dot org
Summary: $this is null inside include
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Centos 6 64-bit
PHP Version: master-Git-2014-10-03 (Git)
Block user comment: N
Private report: N
New Comment:
I can't reproduce this (with neither eval nor require).
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2014-10-03 20:05:55] pegasus at vaultwiki dot org
Description:
------------
Per the description, $this is null inside an eval, even if the eval is in the object's scope.
Test script:
---------------
class Test
{
public $hello = 'hi';
public function test()
{
eval('echo $this->hello;');
}
}
$o = new Test();
$o->test();
Expected result:
----------------
Expect to see printed
hi
Checking $this itself reveals NULL.
Actual result:
--------------
Nothing printed
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68148&edit=1