<?php
class A
{
public static function foo()
{
// some action
}
public static function __callStatic($method, $args)
{
self::foo();
static::$method($args);
}
}
class B extends A
{
public static function bar(){}
}
我搜索PHP公共静态函数处理程序,我尝试__callStatic()
但它只调用私有和受保护的方法。
答案 0 :(得分:3)
只有在类中不存在的方法才会调用__call
and __callStatic
Docs等魔术方法。当正常的方法调用发生时,它们不会被触发。因此,无法通过公共方法实现这一目标。
但是,您可以将这些方法设为私有/受保护,并使用call_user_func
或call_user_func_array
以魔法方式调用它们。当然,这些函数的返回值也应该通过魔术方法返回。