Page 1 of 1

Call function thats stored in a string

Posted: Thu Jun 22, 2006 5:38 pm
by stevieSky
Does anyone know if there is a way to call a php function that is stored in a string...ie


I have an exception table which has the format

ID Exception Name Function Call
1 send_to_top doSendOff



So i check the database and find the function call where exception name = send_to_top
I now have this function in a variable which i want to know if there is a way to now call this function straight from the variable,thanks.

Posted: Thu Jun 22, 2006 5:49 pm
by Benjamin

Code: Select all

eval();
Might be what your looking for..

Posted: Thu Jun 22, 2006 6:25 pm
by feyd
eval(), bad idea. call_user_func(), good idea.

Posted: Thu Jun 22, 2006 6:31 pm
by Benjamin
feyd wrote:eval(), bad idea. call_user_func(), good idea.
Will that work on a function pulled from a database?

Posted: Thu Jun 22, 2006 6:38 pm
by feyd
provided it is just a function name, which, from the steveSky's example, it is. eval() is dangerous business, hands down. Avoid it like the plague.

Posted: Thu Jun 22, 2006 9:52 pm
by Todd_Z
eval should be depreciated - it teaches very bad coding practice.

About the problem: a string is a string independent if its called from a database, flat file, calculation, rss feed, post var. You can also call a function like this:

Code: Select all

$value = $function( $param );

Posted: Mon Jul 10, 2006 11:49 pm
by stevieSky
thanks works great