|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63602 __callStatic does not see $this
Submitted: 2012-11-26 03:39 UTC Modified: 2012-11-26 06:10 UTC
From: stealz at op dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.9 OS: Windows 7
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: stealz at op dot pl
New email:
PHP Version: OS:


 [2012-11-26 03:39 UTC] stealz at op dot pl
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
	static function __callStatic($method, $args) {

class B {
	function test() {

$o = new B();

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-26 06:10 UTC]
-Status: Open +Status: Not a bug
 [2012-11-26 06:10 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

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
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Jun 11 02:03:37 2023 UTC