|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-03 11:59 UTC] reto at buxaprojects dot com
Description:
------------
__call() instead of __callStatic() is called, when we call a static method from a non-static method.
Reproduce code:
---------------
abstract class One
{
public function __call($m, $p)
{
echo '__call(' . $m . ') called' . "\n";
}
public static function __callStatic($m, $p)
{
echo '__callStatic(' . $m . ') called' . "\n";
}
}
class Two extends One
{
public function __construct()
{
$this->normalMethod();
self::staticMethod();
}
private function normalMethod()
{
echo 'normalMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}
private static function staticMethod()
{
echo 'staticMethod() called' . "\n";
parent::a();
self::b();
static::c();
One::d();
Two::e();
}
}
$two = new Two();
Expected result:
----------------
normalMethod() called
__call(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
Actual result:
--------------
normalMethod() called
__call(a) called
__call(b) called
__call(c) called
__call(d) called
__call(e) called
staticMethod() called
__callStatic(a) called
__callStatic(b) called
__callStatic(c) called
__callStatic(d) called
__callStatic(e) called
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 04:00:01 2025 UTC |
Actually, in this particular case, it's completely expected. Class A { public function foo() { } } class B extends A { public function bar() { parent::foo(); // normal call static::foo(); // normal call as well A::foo(); // same here... } } $b = new B; $b->bar(); Now, for BC purposes, it would probably break things if those call suddenly stop calling __call in case A::foo() wasn't defined, which how it currently works in PHP 5.