小编Ser*_*erg的帖子

父类php中的method_exists

我正在尝试使用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)

但以上都没有奏效.我不确定下一步该尝试什么.

谢谢你的帮助!

php parent-child

7
推荐指数
3
解决办法
8162
查看次数

标签 统计

parent-child ×1

php ×1