Php 如何从静态子方法获取类名

Php 如何从静态子方法获取类名,php,oop,inheritance,Php,Oop,Inheritance,您所描述的被称为,它在PHP5.3中可用。是一个伪常量,它总是引用定义它的类。引入了函数,在运行时解析类名 <?php class MyParent { public static function tellSomething() { return __CLASS__; } } class MyChild extends MyParent { } echo MyChild::tellSomething(); (作为旁注:通常方法不需要知道调用它们时

您所描述的被称为,它在PHP5.3中可用。
是一个伪常量,它总是引用定义它的类。引入了函数,在运行时解析类名

<?php
class MyParent {

    public static function tellSomething() {
        return __CLASS__;
    }
}

class MyChild extends MyParent {

}

echo MyChild::tellSomething();
(作为旁注:通常方法不需要知道调用它们时所在的类)

可能的重复
class MyParent {

  public static function tellSomething() {
    return get_called_class();
  }
}

class MyChild extends MyParent {

}

echo MyChild::tellSomething();