使用call_user_func调用对象对象的方法 [英] calling method of object of object with call_user_func
本文介绍了使用call_user_func调用对象对象的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑这个简单的情况:
$ this->方法($ arg1,$ arg2);
解决方案:
code> call_user_func_array(array($ this,'method'),array($ arg1,$ arg2));
考虑这种情况:
$ this-> object->方法($ arg1,$ arg2);
此解决方案是否适用?
call_user_func_array(array($ this-> object,'method'),array($ arg1,$ arg2));
还是应该这样工作?
<$ p $ ($ arg,$ arg2));
编辑:
尝试/捕获可用于SOAP异常,triger同时使用call_user_func? / p>
try {
$ soap_res = call_user_func_array(array($ this-> service,'getBanana'),array 0,10));
} catch(SoapFault $ fault){
die($ fault-> faultstring)
}
解决方案
这应该可以工作:
call_user_func_array ($ this-> object,'method'),array($ arg1,$ arg2));
第一个参数是一个回调类型,包含对象引用和方法名称。
consider this simple scenario:
$this->method($arg1, $arg2);
Solution:
call_user_func_array(array($this,'method'), array($arg1, $arg2));
consider this scenario:
$this->object->method($arg1, $arg2);
Should this solution work?
call_user_func_array(array($this->object,'method'), array($arg1, $arg2));
Or should this work?
call_user_func_array(array($this, 'object','method'), array($arg1, $arg2));
Edit: Will try/catch works for SOAP exception, triger while using call_user_func?
try {
$soap_res = call_user_func_array(array($this->service,'getBanana'), array(0, 10));
} catch (SoapFault $fault) {
die($fault->faultstring)
}
解决方案
This should work:
call_user_func_array(array($this->object,'method'), array($arg1, $arg2));
The first argument is a callback type, containing an object reference and a method name.
这篇关于使用call_user_func调用对象对象的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文