Re: how to trap eval error?

From: Date: Tue, 18 Nov 2003 22:17:56 +0000
Subject: Re: how to trap eval error?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-170186@lists.php.net to get a copy of this message
From: "david" <dzhuo@looksmart.net> > Cpt John W. Holmes wrote: > > From: "david" <dzhuo@looksmart.net> > > > >> i found a solution (hopefully) with: > >> > >> if(function_exists($function)){ > >> eval('$return = $function($input);'); > >> }else{ > >> // function does not exists > >> } > >> > >> which works quit nicely for now. not sure if that's a good thing to do. > > > > Why not just do this: > > > > if(function_exists($function)) > > { $return = $function($input); } > > else > > { //function does not exist; } > > > > because i didn't know PHP can do that. thanks for the tip! any differences > between the 2 version in turns of performance and safety? You're not invoking eval() for one thing and there's less of a security risk compared to passing variables into an eval() function. ---John Holmes...

« previous php.general (#170186) next »