EOB
EOB

Reputation: 3085

Call a function wihich is represented as string?

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

Answers (1)

Kris
Kris

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

Related Questions