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.
You can do this (although a little more than "simple") with 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With