![](/img/trans.png)
[英]PHP extend a class method that is called from another class which extends it and calls the method with parent::method
[英]Parent class's method called by using which child class in php?
假设我有以下场景。
class Base {
public static function functionA() {
// I want to know this method is called by which child class's instance
}
}
class Child extends Base {
public static function someFunc() {}
}
class AnotherChild extends Base {
public static function someOtherFunc() {}
}
// Now I call the static function from the Base class
Child::functionA();
AnotherChild::functionA();
通过使用上面的示例,我如何检测方法functionA()
是通过使用Child
或AnotherChild
class 调用的。这可能吗?
有多种方法可以获取 class 名称,但我现在唯一获取实际 class 的方法是:
class Base {
public static function functionA() {
echo get_called_class();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.