I have to dynamically try, if function is callable (not only if exists, but if is callable). This is my code:
try {
call_user_func($function, $arguments->arg);
} catch (Exception $e) {
$condition = $this->_object->getContent("phpCall", "return");
}
$function
and $arguments->arg
are dynamic variables, for example $function
contains md5
and $arguments->arg
contains 123
.
I know that function md5
exists in PHP, but I get this error: Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in...
Any ideas?
Use is_callable
if (is_callable($function)){
//do stuff here
}
If you're going to pass it to call_user_func, make sure $function is a string. Alternatively, you could just do:
$function($args);
Sounds like call_user_func expects a string with the name of the function to be called. Are you instead sending a function pointer?