如何从PHP中的抽象类中获取接口名称
在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
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;
}