| 
	
 | 
 Posted by Janwillem Borleffs on 06/14/34 11:23 
Andreas Thiele wrote: 
>> The eval is useless here. 
>> ... 
> 
> No, it creates local variables. These were meant to be used in some 
> complex processing directly following, something like 
> 
> if ($foo == 3) 
>   if (some_func($bar) == 4 && $baz ==2) ... // I mean a lot of 
> conditions or other uses following. 
> 
 
I don't see what's the benefit of using: 
 
eval(abind("arr", array("foo", "bar", "baz"))); 
 
instead of using: 
 
abind("arr", array("foo", "bar", "baz")); 
 
Besides, in most cases you can use call_user_func or call_user_func_array to  
accomplish what you want to do instead of using eval for this. 
 
> I didn't expect this. Are you sure? I mean php is an interpreter, or 
> does it compile things? If it is a pure interpreter, I would expect 
> the parser itself using eval a lot. So why should this be especially 
> expensive? Do you have any hints on something I might read regarding 
> this? 
> 
 
When you use eval in your code, it must be evaluated before the engine can  
continue the processing of your script. One of the side-effects is that it's  
much slower as the following test will show: 
 
<?php 
$start = array_sum(explode(' ', microtime())); 
 
for ($i = 0; $i < 100; $i++) { 
 eval('$foo = "bar";'); 
} 
 
$end = array_sum(explode(' ', microtime())) - $start; 
echo 'Finished in ', round($end, 5), " seconds\n"; 
 
$start = array_sum(explode(' ', microtime())); 
 
for ($i = 0; $i < 100; $i++) { 
 $foo = "bar"; 
} 
 
$end = array_sum(explode(' ', microtime())) - $start; 
echo 'Finished in ', round($end, 5), " seconds\n"; 
 
?> 
 
 
JW
 
[Back to original message] 
 |