|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42559 $this leaks to scope of statically called method
Submitted: 2007-09-05 10:21 UTC Modified: 2007-09-05 12:34 UTC
From: arnout at argeweb dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4 OS: BSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: arnout at argeweb dot nl
New email:
PHP Version: OS:


 [2007-09-05 10:21 UTC] arnout at argeweb dot nl
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:

class instance{
    var $test = 'test';
    function do_thing(){

// 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();

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/>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-05 12:34 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Mark your function as static and you get an error telling "Using $this when not in object context"
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 02:01:30 2024 UTC