Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP继承方法或父类名称_Php_Oop_Inheritance - Fatal编程技术网

PHP继承方法或父类名称

PHP继承方法或父类名称,php,oop,inheritance,Php,Oop,Inheritance,我将尝试用代码来解释我的问题: class A extends masterClass { function api() { die(__CLASS__); /* rest of the code here ... */} } class B extends A { /* rest of the code here ... */ } $obj = new B(); $obj->api(); // Should be "B" (name of last child

我将尝试用代码来解释我的问题:

class A extends masterClass  
{
 function api()
 { 
  die(__CLASS__); 
 /* rest of the code here ... */}
}

class B extends A
{
 /* rest of the code here ... */
}

$obj = new B();
$obj->api(); // Should be "B"  (name of last child class)
有什么“最佳”解决方案吗? 谢谢

您可以使用或代替
\uuuu CLASS\uuuu