如何從擴展的 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章