#42559 [Opn->Bgs]: $this leaks to scope of statically called method
| From: | johannes@php.net | Date: | Wed, 05 Sep 2007 12:34:43 +0000 |
| Subject: | #42559 [Opn->Bgs]: $this leaks to scope of statically called method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-117164@lists.php.net to get a copy of this message | ||
ID: 42559
Updated by: johannes@php.net
Reported By: arnout at argeweb dot nl
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: BSD
PHP Version: 5.2.4
New Comment:
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
Mark your function as static and you get an error telling "Using $this
when not in object context"
Previous Comments:
------------------------------------------------------------------------
[2007-09-05 10:21:29] arnout at argeweb dot nl
Description:
------------
Within methods the $this variable seems to leak into the scope of
statically called methods. Even when the called static function is in an
entirely different class.
It only happens when the statically called method is not explicitly
defined as static.
Reproduce code:
---------------
<?php
class instance{
var $test = 'test';
function do_thing(){
static_class::func();
}
}
// happens with and without the abstract keyword
abstract class static_class{
function func(){
echo 'output: '.$this->test.'<br/>';
echo 'class: '.get_class( $this ).'<br/>';
echo 'How did I get here?<br/>';
}
}
$instance = new instance();
$instance->do_thing();
?>
Expected result:
----------------
A warning telling me I shouldn't use $this in a static scope.
Or just a notice saying $this is not defined / not an object.
Actual result:
--------------
output: test<br/>
class: instance<br/>
How did I get here?<br/>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42559&edit=1