热搜:NVER node 开发 php

php call_user_func_array怎么调用对象本类的方法

2024-07-25 16:30:01
php call_user_func_array怎么调用对象本类的方法

function callback($object){        if ($object != null && method_exists($object, 'returnData')) {            //可以执行到这里            call_user_func_array(array($object, 'returnData'), array(ERROR_SOFT_NO_EXIST));        }    }


我在一个类中调用callback($this),method_exists返回true,但随后的call_user_func_array总是报错:Think\Controller:returnData方法不存在!

Think\Controller:returnData是这个类的基类,returnData方法在本类中,怎么才能调用到本类的这个方法,而不是调用基类的方法呢?


回复讨论(解决方案)

已解决,这样调用的方法必须是公开方法