簡體   English   中英

如何在PHP接口范圍之外獲取接口名稱的字符串值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM