您应该能够调用
ReflectionMethod::getDeclaringClass()来获取声明该方法的类.然后调用
ReflectionClass::getParentClass()来获取父类.最后,对
ReflectionClass::hasMethod()的调用将告诉您该方法是否在父类中声明.
例:
class Foo {
function abc() {}
}
class Bar extends Foo {
function abc() {}
function def() {}
}
$bar = new Bar();
$meth = new ReflectionMethod($bar, "abc");
$cls = $meth->getDeclaringClass();
$prnt = $cls->getParentClass();
if ($cls->hasMethod($meth->name)) {
echo "Method {$meth->name} in Bar\n";
}
if ($prnt->hasMethod($meth->name)) {
echo "Method {$meth->name} in Foo\n";
}
$meth = new ReflectionMethod($bar, "def");
$cls = $meth->getDeclaringClass();
$prnt = $cls->getParentClass();
if ($cls->hasMethod($meth->name)) {
echo "Method {$meth->name} in Bar\n";
}
if ($prnt->hasMethod($meth->name)) {
echo "Method {$meth->name} in Foo\n";
}