Re: checking if a function exists before doing an eval
| From: | Justin French | Date: | Thu, 08 Aug 2002 11:12:16 +0000 |
| Subject: | Re: checking if a function exists before doing an eval | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111626@lists.php.net to get a copy of this message | ||
how about the function function_exists() ?
it's all in the manual:
http://www.php.net/manual/en/function.function-exists.php
Justin French
on 08/08/02 9:10 PM, Henry (henry@teacake.f9.co.uk) wrote:
> Hi All,
>
> I'm trying to evaluate a function (but only if it exists!).
>
> something like (pseudo code):
>
> function animal_is_bear($name)
> {
> return $name."is a big grizzley bear";
> }
>
> function animal_is_goat($name)
> {
> return $name."is a wee mountain goat";
> }
>
>
> $animal_type="goat";
> $animal_name="billy";
>
> echo eval("return
> animal_is_".$animal_type."(".$animal_name.");");
>
>
> $animal_type="puma";
> $animal_name="sinbad";
>
> echo eval("return
> animal_is_".$animal_type."(".$animal_name.");");
>
>
> The first eval should return "billy is a wee mountain goat";
>
> But the last eval causes a problem because the function animal_is_puma does
> not exist.
>
> How do I check if the funciton exists before I eval?
>
> Or am I better of having an associative array of functions?
>
> TIA
>
> Henry
>
>
>
>