本文介紹了在 PHP 中只獲取一個類的聲明方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
您好,我只需要獲取類中聲明的方法,而不是繼承的方法.我需要這個用于 cakePHP.我正在獲取所有控制器,加載它們并從這些控制器中檢索方法.但不僅是聲明的方法來了,還有繼承的方法.
Hello I need to get only the methods declared in a class, and not the inherited methods. I need this for cakePHP. I am getting all the controllers, loading them and retrieving the methods from those controllers. But not only are the declared methods coming, but also the inherited ones.
是否有任何方法可以只獲取聲明的方法.
Is there any method to get only declared methods.
推薦答案
您可以使用 ReflectionClass
function getDeclaredMethods($className) {
$reflector = new ReflectionClass($className);
$methodNames = array();
$lowerClassName = strtolower($className);
foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (strtolower($method->class) == $lowerClassName) {
$methodNames[] = $method->name;
}
}
return $methodNames;
}
這篇關于在 PHP 中只獲取一個類的聲明方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!