|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62393 __callStatic from a derived class object context calls __call instead
Submitted: 2012-06-22 10:04 UTC Modified: 2012-06-23 06:39 UTC
From: andre-desch at t-online dot de Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.4 OS: Windows 7 Prof.
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
47 + 17 = ?
Subscribe to this entry?

 [2012-06-22 10:04 UTC] andre-desch at t-online dot de
If You define both the magic function for static and dynamic calls for a class and 
then call a static function from a derivate's method, not the static but the 
dynamic magic function is called.

Test script:

class MyBaseClass {

	public static function __callStatic($what, $args)
		return 'static call';
	public function __call($what, $args)
		return 'dynamic call';


class MyDerivedClass extends MyBaseClass {

	function someAction()
		//here I call a base class' static function
		//it returns "dynamic call" instead of "static call"
		return MyBaseClass::Foo();


$bar = new MyDerivedClass();
echo $bar->someAction();


Expected result:
static call

Actual result:
dynamic call


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-22 11:15 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

This is due to the way calls to parent::foo() and such are handled, these look like static calls but in fact aren't.
 [2012-06-22 11:15 UTC]
-Status: Open +Status: Not a bug
 [2012-06-22 11:57 UTC] john dot papaioannou at gmail dot com
Excuse me, but how exactly does parent::Foo() come into the discussion?

The test code is calling MyBaseClass::Foo(), which clearly is a static call.
 [2012-06-22 14:46 UTC]
> The test code is calling MyBaseClass::Foo(), which clearly is a static call.

You are mistaken. MyBaseClass::Foo() is not necessarily a static call. Namely, if $this is of type MyBaseClass or a subclass thereof and there's no explicit static method MyBaseClass::Foo(), then MyBaseClass::Foo() is an instance call.
 [2012-06-23 06:39 UTC]
if there is a calling scope, then :: is not a static call.

if there is no calling scope, then :: is a static call.

the key point is the calling scope, not the "::" .

 [2012-06-23 13:44 UTC] andre-desch at t-online dot de
It is a static call if You use an empty proxy class like below. The only 
difference in scope is, that MyProxyClass is not directly in the hierachy tree 
above the calling method's class. Please explain why this is intended.

class MyProxyClass extends MyBaseClass { //empty }

class MyDerivedClass extends MyBaseClass {
	function someAction()
		return MyProxyClass::Foo();
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 20:01:30 2024 UTC