Reputation: 3085
can I call a method that is represented as string?
Example:
$function = '$this->myfunction($myparam)';
How could I call myfunction with myparam? Possible?
Thanks :)
Upvotes: 0
Views: 59
Reputation: 8868
You can use the call_user_func();
function of PHP.
eg.,
function callMe($message)
{
echo "My Function was called with arg:".$message;
}
and you can call it like
call_user_func("callMe","MyMessage");
and it will return any value, that the function returns.
Also, if you want to call with multiple arguments or array , you can use
call_user_func_array()
Hope you can get a detailed implementation of these in www.php.net
Upvotes: 1