I’m trying to get a list of methods that were actually defined in a definition for a given class (not just inherited from another class). For example:
class A
{ function bob()
{
}
}
class B extends A
{ function rainbrew()
{
}
}
class C extends B
{ function bob()
{
}
}
echo print_r(get_defined_class_methods("A"), true)."<br>\n";
echo print_r(get_defined_class_methods("B"), true)."<br>\n";
echo print_r(get_defined_class_methods("C"), true)."<br>\n";
I’d like the result to be:
array([0]=>bob)
array([0]=>rainbrew)
array([0]=>bob)
Is this possible?
You can use Reflection for this:
This will actually give you an array of ReflectionMethod objects, but you can easily extrapolate what you need from there. ReflectionMethods provide a
getDeclaringClass()function for this, so you can find which functions were declared in which class:This will give:
So, as a final solution, try this: