micah1701 Posted October 4, 2011 Share Posted October 4, 2011 So i need to dynamically call a function in my object, depending on certain parameters. Currently, I'm doing this: <?php $myObject = new Object_Class; $the_function_to_call = "do_something"; // this is not really a static variable; it changes each time the script loads. eval("\$myObject->". $the_function_to_call ."();"); // run $myObject->do_something(); ?> This works fine but I'd rather not use eval() if I can help it. Is there an easy way to do this that I'm just missing? Quote Link to comment https://forums.phpfreaks.com/topic/248447-call-function-dynamically-without-using-eval/ Share on other sites More sharing options...
KevinM1 Posted October 4, 2011 Share Posted October 4, 2011 You're overthinking it: $myObject->$the_function_to_call(); Quote Link to comment https://forums.phpfreaks.com/topic/248447-call-function-dynamically-without-using-eval/#findComment-1275828 Share on other sites More sharing options...
micah1701 Posted October 4, 2011 Author Share Posted October 4, 2011 wow! I knew I was missing something simple. thank you so much!!! Quote Link to comment https://forums.phpfreaks.com/topic/248447-call-function-dynamically-without-using-eval/#findComment-1275830 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.