问题描述
我需要使用call_user_func。我将需要在具有5个参数的单独类中的单独文件中调用函数。我在这里。有什么办法吗?
I need to use call_user_func . I will need to call a function in a separate file in separate class with 5 arguments . I couldnt find any example here http://php.net/manual/en/function.call-user-func.php . IS there any way to do this ?
推荐答案
我个人使用 call_user_func_array
$ result = call_user_func_array(array($ objectInstance,'objectMethod'),array('parameter one','parameter two')) ;
如果该方法是静态方法,请用名称替换 $ objectInstance
使用的类别。您也可以使用独立函数:
If the method is a static one, replace $objectInstance
with the name of the class being used. You can also use stand-alone functions too:
$ result = call_user_func_array('functionName',array('parameter one','parameter two '));
希望这有意义吗? :]
Hope this makes sense? :]
不过,将来尝试向我们展示您的工作和尚未做的事情:]
However in the future, try and show us what you have and haven't done :]
这篇关于PHP call_user_func与类和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!