note 9558 modified in eval by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Sat, 11 Nov 2000 00:52:24 +0000 |
| Subject: | note 9558 modified in eval by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7590@lists.php.net to get a copy of this message | ||
[Editor's note: I am including here part of the (removed) comment by kenny@yellowzone.com to
which this note makes reference:
--- kenny@yellowzone.com wrote:
> The following tooks me an hour to figure out:
>
> If you have a variable $hdl contains the
> name of the function that you want to
> execute, and you have the variable $var
> contains the values that need to be passed into the
> function in $hdl, the
> way to execute them is:
>
> eval ("$hdl (\$var);");
>
> So, you can have functions's names saved
> in a database, and pass in values come from
> somewhereelse, and dynamically choose the right
> functions to process the input data.
This is the expected behavior due to the parsing/interpolation of variables referenced in a doble
quoted string, if you do need to avoid the parsing, you need to escape the variable name (as
kenny@yellowzone.com example does), or simple concatenate the string using single quotes, e.g.:
eval ($hdl.' ($var);');
Nothing new here that is not already discussed in the manual elsewhere.
]
...or you can simply do this:
$hdl($var);
...provided $hdl is a user-defined function, and one of PHP's built-in functions.
http://www.php.net/manual/function.eval.php