Re: Call function and get return...
| From: | Lars Torben Wilson | Date: | Wed, 16 Aug 2000 08:28:24 +0000 |
| Subject: | Re: Call function and get return... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11947@lists.php.net to get a copy of this message | ||
Martin Thoma writes:
> Hello !
>
> I need to call a function "DoIt" with a function a an argument.
> This works fine, when calling DoIt("f2();") and using eval($func) in
> DoIt to call the function (like in the example below):
>
> function DoIt($func)
> { eval($func);
> }
>
> function f1()
> {}
> function f2()
> {}
> function f3()
> {}
>
> Now I need to get back a return-value from my functions, for example:
> function f2()
> { return 2;
> }
>
> But "eval" doesn't return any results... How is it done ?
>
> Regards
>
> Martin
It's easier than that. :) Use variable functions instead--no messing
around with eval()..
<?php
error_reporting(E_ALL);
function f1()
{
return "Returning from f1()\n";
}
function f2()
{
return "Returning from f2()\n";
}
function f3()
{
return "Returning from f3()\n";
}
function DoIt($func) {
if (function_exists($func)) {
echo $func();
}
}
DoIt('f2');
?>
Cheers,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+