gpt4 book ai didi

php - 仅获取 PHP 中类的声明方法

转载 作者:可可西里 更新时间:2023-11-01 13:15:37 25 4
gpt4 key购买 nike

您好,我只需要获取类中声明的方法,而不是继承的方法。我需要这个用于 cakePHP。我正在获取所有 Controller ,加载它们并从这些 Controller 中检索方法。但是不仅声明的方法来了,继承的方法也来了。

是否有任何方法可以只获取声明的方法。

最佳答案

你可以用 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 - 仅获取 PHP 中类的声明方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3712671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com