[英]how to get string value for the interface name outside the interface scope in PHP
我想將接口名稱轉換為string
。
get_class
函數需要接口中的對象,而不是接口本身。
從理論上講,此示例顯示了我要執行的操作:
<?php
interface MyInterface
{
/* Some code goes here */
}
$name = get_interface_name(MyInterface); # $name should hold string 'MyInterface'
?>
謝謝Ogail
使用Reflectionclass http://php.net/manual/en/reflectionclass.getinterfacenames.php
interface MyInterface
{
/* Some code goes here */
}
class Sub implements MyInterface { }
$getinterface = new ReflectionClass("Sub");
var_dump($getinterface->getInterfaceNames());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.