您好我只需要获取类中声明的方法,而不是继承的方法.我需要这个用于cakePHP.我正在获取所有控制器,加载它们并从这些控制器中检索方法.但不仅是声明的方法即将到来,还有继承的方法.
是否有任何方法只获取声明的方法.
你可以这样做(虽然比"简单"更多) 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;
}
Run Code Online (Sandbox Code Playgroud)