You are here: Re: Bind variables to a simple array « PHP Programming Language « IT news, forums, messages
Re: Bind variables to a simple array

Posted by Janwillem Borleffs on 11/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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация