Eddy999999 Posted May 12, 2007 Share Posted May 12, 2007 I am trying to be able to execute portions of code stored in a database using eval(). My question is, if I create a function inside of an eval() statement, can it be executed from code outside of the eval statement. For example, if I have the following code in my database: function test() { echo 'test'; } And retrieve it from the database as $test, and have this code: eval($test); test(); Should the function call work correctly? The reason I ask is because when I tried to do this, I got a "Call to undefined function:" error, and I'm trying to figure out if it's something I did wrong, or if I just can't do that. Any help, or links to somewhere with some info, would be greatly appreciated, although I wasn't able to find anything that helped with a quick google search. Thanks, Eddy Quote Link to comment https://forums.phpfreaks.com/topic/51092-functions-created-in-eval/ Share on other sites More sharing options...
utexas_pjm Posted May 12, 2007 Share Posted May 12, 2007 I believe it's possible as this code executed for me (using PHP5): <?php eval ('function foo () { echo "Bar"; }'); foo(); // Prints Bar ?> I'd check the contents of your $test variable to make sure it is set. Best, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/51092-functions-created-in-eval/#findComment-251501 Share on other sites More sharing options...
Eddy999999 Posted May 12, 2007 Author Share Posted May 12, 2007 That was my problem Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/51092-functions-created-in-eval/#findComment-251551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.