lets assume that i have function named printuser()
now if i have string like
$myFunction = 'printuser()';
how i can run this string as function ? so it should do the printuser() function
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you just want
$myFunctionto specify which function to run, you can do something likeThis is called a “variable function“, and is slightly less dangerous than
eval. (You can call any existing function, but you can’t run arbitrary code.)Be warned, though: if
printuserdoesn’t exist, the script will die. You might consider checking for the function’s existence before calling it.Replace the
throwwith whatever you want to do if the function isn’t there. That’s just an example.