問題:
I have two classes: Action
and MyAction
.我有兩個類: Action
和MyAction
。 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?有沒有可能的方法來做到這一點?