如何从扩展的 PHP 类中的静态调用中获取类名? - How can I get the classname from a static call in an extended PHP class?

问题:

I have two classes: Action and MyAction .我有两个类: ActionMyAction The latter is declared as:后者声明为:

class MyAction extends Action {/* some methods here */}

All I need is method in the Action class (only in it, because there will be a lot of inherited classes, and I don't want to implement this method in all of them), which will return classname from a static call.我所需要的只是Action类中的方法(只在其中,因为会有很多继承的类,我不想在所有这些类中都实现这个方法),它将从静态调用中返回类名。 Here is what I'm talking about:这就是我要说的:

Class Action {
 function n(){/* something */}
}

And when I call it:当我调用它时:

MyAction::n(); // it should return "MyAction"

But each declaration in the parent class has access only to the parent class __CLASS__ variable, which has the value “Action”.但是父类中的每个声明只能访问父类__CLASS__变量,该变量的值为“Action”。

Is there any possible way to do this?有没有可能的方法来做到这一点?


解决方案:

参考: https://stackoom.com/en/question/27of
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章