In order to optimize my code, how can I write the last two lines of code in one statement?
$v1 = functionName;
$strR = "get".$v1;
echo $obj->$strR();
As I want to get $obj->getfunctionName().
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.
You can enclose it in
{}to shorten your code, but this will not make a significant difference (if any at all) in terms of execution speed:This functionality is described in user-contributed comments on the PHP5 OOP introductory page, though I do not consider that official documentation.