字符串形式:
function test($str) {
return $str;
}
$ree = 'you';
$res = call_user_func('test',$ree);
echo $res;
数组形式:
class myClass {
function test($res) {
return $res;
}
}
$str = 'you';
$res = call_user_func([myClass,'test'],$str);
echo $res; //you
如何判断是否为可回调函数
bool is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] )
name
要检查的回调函数。
syntax_only
如果设置为 TRUE,这个函数仅仅验证 name 可能是函数或方法。
callable_name
接受“可调用的名称”。
return
如果 name 可调用则返回 TRUE,否则返回 FALSE
<?php
// is_callable();
$bool = is_callable(urlencode); // true
$bool = is_callable(urlencode,false);