Does using more variables have any impact on the efficiency of the code?
I.E. does this code:
function get_random_string($valid_chars, $length)
{
$random_string = "";
$num_valid_chars = strlen($valid_chars);
for ($i = 0; $i < $length; $i++)
{
$random_pick = mt_rand(1, $num_valid_chars);
$random_char = $valid_chars[$random_pick-1];
$random_string .= $random_char;
}
return $random_string;
}
work more efficiently than this:
function get_random_string($valid_chars, $length)
{
$random_string = "";
for ($i = 0; $i < $length; $i++)
$num_valid_chars=strlen($valid_chars);
{
$random_string .= $valid_chars[mt_rand(1, $num_valid_chars)-1];
}
return $random_string;
}
In the end, you won’t notice the difference unless your real code completly different from the example.
Remember that even if PHP is not being compiled per se, the code still gets parsed and op-code compiled and even cached. The result can be dramaticaly different from what you coded in the first place.
Your job as a developper is to make clean, readable code that answer’s the client request. Obviously, don’t use techniques that forcefuly makes the code bloaty and slow, the rest is the Zend Optimizer’s job, don’t worry about it.