In this case, the child of the class must extend the parent
class Parent
{
public function hello()
{
}
}
class Child extends Parent
{
}
$child = new Child();
if(method_exists($child,"hello"))
{
$child->hello();
}
Refresh This will have the same effect as method_exists.
function parent_method_exists($object,$method)
{
foreach(class_parents($object) as $parent)
{
if(method_exists($parent,$method))
{
return true;
}
}
return false;
}
if(method_exists($child,"hello") || parent_method_exists($object,"hello"))
{
$child->hello();
}
Just updated from Wrikken post
source
share