Edit report at https://bugs.php.net/bug.php?id=63602&edit=1

 ID:                 63602
 Updated by:         [email protected]
 Reported by:        stealz at op dot pl
 Summary:            __callStatic does not see $this
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Windows 7
 PHP Version:        5.4.9
 Block user comment: N
 Private report:     N

 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

you should not use $this in a static method.

you should see a strict warning for this like:
PHP Strict Standards:  Non-static method A::foo() should not be called 
statically, 
assuming $this from incompatible context

for your question:
__callStatic does not parse the this_ptr for static calls


Previous Comments:
------------------------------------------------------------------------
[2012-11-26 03:39:25] stealz at op dot pl

Description:
------------
When we call the method foo() of some class A in a static context inside the 
object B, the method can see $this as an object B. However, when method doesn't 
exist and __callStatic is triggered, $this is undefined. Why is that so?

Test script:
---------------
abstract class A {
        function foo() { # non-static on purpose
                var_dump($this);
        }
        static function __callStatic($method, $args) {
                var_dump($this);
        }
}

class B {
        function test() {
                A::foo();
                A::someMethod();
        }
}

$o = new B();
$o->test();

Expected result:
----------------
object(B)[4]
object(B)[4]

Actual result:
--------------
object(B)[4]
null


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63602&edit=1

Reply via email to