get_called_class() 获取调用该方法的类,如果是在子类中调用父类方法,则返回子类的类名。

或者用static关键字:static::class

如果有多个子类,要在父类中调用子类方法,下面代码可实现:

classparent{abstractprotectedstaticfunctiongetFunc($action);publicstaticfunctioncall($action){//调用子类静态方法,唯一的方式$func=static::getFunc($action);if(!$func){exit();}try{$reflectionMethod=newReflectionMethod(get_called_class(),$func);}catch(ReflectionException$e){exit();}return$reflectionMethod->invoke(null/*,$paras*/);}}classsonextendsparent{publicstaticfunctiongetFunc($action){return"hello";}}