You can get the ReflectionMethod
object for the method you are interested in, and then use getPrototype()
to get the ReflectionMethod
of the method in the parent class. If the method does not override a method in the parent, this will throw a ReflectionClass
exception.
The following example code will create an array with method name as key and the class which defined the implementation in use for the reflected class.
class Base {
function basemethod() {}
function overridein2() {}
function overridein3() {}
}
class Base2 extends Base {
function overridein2() {}
function in2only() {}
function in2overridein3 () {}
}
class Base3 extends Base2 {
function overridein3() {}
function in2overridein3 () {}
function in3only() {}
}
$rc = new ReflectionClass('Base3');
$methods = array();
foreach ($rc->getMethods() as $m) {
try {
if ($m->getPrototype()) {
$methods[$m->name] = $m->getPrototype()->class;
}
} catch (ReflectionException $e) {
$methods[$m->name] = $m->class;
}
}
print_r($methods);
This will print:
Array
(
[overridein3] => Base
[in2overridein3] => Base2
[in3only] => Base3
[overridein2] => Base
[in2only] => Base2
[basemethod] => Base
)