我必须动态尝试,如果函数是可调用的(不仅如果存在,但是如果是可调用的).这是我的代码:
try {
call_user_func($function, $arguments->arg);
} catch (Exception $e) {
$condition = $this->_object->getContent("phpCall", "return");
}
Run Code Online (Sandbox Code Playgroud)
$function并且$arguments->arg是动态变量,例如$functioncontains md5和$arguments->argcontains 123.
我知道md5PHP中存在该函数,但是我收到此错误:
Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in...
有任何想法吗?
if (is_callable($function)){
//do stuff here
}
Run Code Online (Sandbox Code Playgroud)
如果你要将它传递给call_user_func,请确保$ function是一个字符串.或者,您可以这样做:
$function($args);
Run Code Online (Sandbox Code Playgroud)