Jump to content

call function dynamically without using eval()


micah1701

Recommended Posts

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.