Monday, July 16, 2012

Calling Functions Using Variable In Php

Problem Statement:
In Order to optimize my code , I was thinking how to write the last two lines of code in one statement.
$v1 = functionName;
$strR = "get".$v1;
echo $obj->$strR();     
as i wana get $obj->getfunctionName();


Solution :
echo $obj->{"get" . $v1}();


Reason :
1. Bench marking reports suggest the solution is optimized.
2. Code looks more professional.

php elephant

No comments:

Post a Comment