调用一个函数,该函数表示为字符串


Call a function wihich is represented as string?

我可以调用表示为字符串的方法吗?

例:

$function = '$this->myfunction($myparam)';

我怎样才能用myparam调用myfunction?可能?

谢谢:)

您可以使用 PHP 的call_user_func();函数。

例如,

function callMe($message)
{
echo "My Function was called with arg:".$message;
}

你可以这样称呼它

call_user_func("callMe","MyMessage");

它将返回函数返回的任何值。

另外,如果要使用多个参数或数组调用,则可以使用

call_user_func_array()

希望你能在 www.php.net 中得到这些的详细实现