Call function thats stored in a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevieSky
Forum Newbie
Posts: 10
Joined: Wed Apr 26, 2006 4:18 pm

Call function thats stored in a string

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

eval();
Might be what your looking for..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

eval(), bad idea. call_user_func(), good idea.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

feyd wrote:eval(), bad idea. call_user_func(), good idea.
Will that work on a function pulled from a database?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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 );
stevieSky
Forum Newbie
Posts: 10
Joined: Wed Apr 26, 2006 4:18 pm

Post by stevieSky »

thanks works great
Post Reply