繁体   English   中英

php中哪个child class调用了父类的方法?

[英]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()是通过使用ChildAnotherChild class 调用的。这可能吗?

有多种方法可以获取 class 名称,但我现在唯一获取实际 class 的方法是:

class Base {
    public static function functionA() {
        echo get_called_class();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM