我正在尝试使用php函数method_exists,但我需要检查该方法是否存在于对象的父类中.
所以:
class Parent
{
public function myFunction()
{
/* ... */
}
}
class Child extends Parent
{
/* ... */
}
$myChild = new Child();
if (method_exists($myChild, 'myFunction'))
{
/* ... */
}
if (method_exists(Parent, 'myFunction'))
{
/* ... */
}
if (is_callable(array('Parent', 'myFunction'))
{
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
但以上都没有奏效.我不确定下一步该尝试什么.
谢谢你的帮助!