Bug #62393 [Nab]: __callStatic from a derived class object context calls __call instead

From: Date: Fri, 22 Jun 2012 14:46:00 +0000
Subject: Bug #62393 [Nab]: __callStatic from a derived class object context calls __call instead
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-171453@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62393&edit=1

 ID:                 62393
 Updated by:         cataphract@php.net
 Reported by:        andre-desch at t-online dot de
 Summary:            __callStatic from a derived class object context
                     calls __call instead
 Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   Windows 7 Prof.
 PHP Version:        5.4.4
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2012-06-22 11:57:35] 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 11:15:16] johannes@php.net

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

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 10:04:14] andre-desch at t-online dot de

Description:
------------
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:
---------------
<?php

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


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



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


Thread (6 messages)

« previous php.bugs (#171453) next »