On Wed, Mar 19, 2008 at 3:22 PM, chetan rane <[EMAIL PROTECTED]> wrote: > HI All > > I have the follwoing code > > function cleanufx($str){ > return ucase($str); > } > > $value="xyz"; > $var ="ufx"; > $fn="clean$var($value); > $val =eval("$fn;"); > echo $val; > > can anyone tell me what is wrong in this as the eval is returning 0 (false); >
Lots. For starters, this won't even compile. You aren't closing quotes on the line where you assign a value to $fn. You also don't need quotes around $fn in your eval statement. There isn't a PHP function named ucase (unless you declared it elsewhere). I'm guessing you meant strtoupper(). Besides, eval opens up potential security problems that can easily be avoided for what you are trying to do here. Assuming your actual logic is more complex than the example you have shown here and this approach is actually necessary, why not do this? function cleanufx($str){ return strtoupper($str); } $value="xyz"; $var ="ufx"; $fn="clean$var"; $val = call_user_func($fn, $value); echo $val; Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php