Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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_Function_Oop_Interface_Abstract Class - Fatal编程技术网

如何从PHP中的抽象类中获取接口名称

如何从PHP中的抽象类中获取接口名称,php,function,oop,interface,abstract-class,Php,Function,Oop,Interface,Abstract Class,在php中,在不创建新对象的情况下获取接口名是可能的??例如: interface my_interface{} abstract class foo implements my_interface{ public static function get_interface(){ // here return name of interface } } class bar extends foo{} echo bar::get_inte

在php中,在不创建新对象的情况下获取接口名是可能的??例如:

interface my_interface{}

abstract class foo implements my_interface{

      public static function get_interface(){
             // here return name of interface
      }

}

class bar extends foo{}

echo bar::get_interface();
预期产出:

 my_interface
利用课堂

代码。。
请参见

谢谢,我认为反射类需要对象的新实例。无论如何,谢谢你的回答
$rc1 = new ReflectionClass("foo");
echo $rc1->getInterfaceNames()[0];
<?php
interface my_interface{}

abstract class foo implements my_interface{

    public static function get_interface(){
        // here return name of interface
    }

}

$rc1 = new ReflectionClass("foo");
echo $rc1->getInterfaceNames()[0];
my_interface
$r = new ReflectionClass(get_class()); // or get_called_class
foreach ($r->getInterfaceNames() as $name) {
    echo $name;
}