考虑这个简单的场景:
$this->method($arg1, $arg2);
解决方法:
call_user_func_array(array($this,'method'), array($arg1, $arg2));
考虑这个场景:
$this->object->method($arg1, $arg2);
这个解决方案应该有效吗?
call_user_func_array(array($this->object,'method'), array($arg1, $arg2));
或者这应该行得通吗?
call_user_func_array(array($this, 'object','method'), array($arg1, $arg2));
编辑: try/catch 是否适用于 SOAP 异常,在使用 call_user_func 时触发?
try {
$soap_res = call_user_func_array(array($this->service,'getBanana'), array(0, 10));
} catch (SoapFault $fault) {
die($fault->faultstring)
}
最佳答案
这应该可行:
call_user_func_array(array($this->object,'method'), array($arg1, $arg2));
第一个参数是 callback type ,包含一个对象引用和一个方法名。
关于php - 使用 call_user_func 调用对象对象的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/980708/