Re: Dynamic Function with return?

From: Date: Sat, 28 Aug 2004 00:03:23 +0000
Subject: Re: Dynamic Function with return?
Groups: php.general 
Request: Send a blank email to php-general+get-194977@lists.php.net to get a copy of this message
> -----Original Message----- > From: bskolb [mailto:php@bskolb.com] > Sent: Friday, August 27, 2004 3:59 PM > To: php-general@lists.php.net > Subject: [PHP] Dynamic Function with return? > > > Sample Code: > > //================================ > <?PHP // version 4.3.6 > function testFunction($foo) { > return $foo=="TEST"; > } > > function wrapper($foofunc, $foovar) { > return eval("return $foofunc($foovar);"); > } > > echo wrapper("testFunction", "TEST"); > ?> > //================================ > > This code works. It calls the function and > receives the appropriate return value. > > But, is there a better way of doing this? > It seems a bit round-a-bout. Did you already try this? function wrapper($foofunc, $foovar){ return $foofunc($foovar); } http://us3.php.net/manual/en/functions.variable-functions.php Maybe I'm missing something, but I don't see the need for the eval since PHP supports variable function names.

« previous php.general (#194977) next »