From:             arnout at argeweb dot nl
Operating system: BSD
PHP version:      5.2.4
PHP Bug Type:     Class/Object related
Bug description:  $this leaks to scope of statically called method

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 bug report at http://bugs.php.net/?id=42559&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42559&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42559&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42559&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42559&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42559&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42559&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42559&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42559&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42559&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42559&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42559&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42559&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42559&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42559&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42559&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42559&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42559&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42559&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42559&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42559&r=mysqlcfg

Reply via email to