Possible Duplicate:
Call php class method from string with parameter
I am trying to call a method in a class from a string of the method and a string of the class, by means of call_user_func_array()
For Example:
$class = 'Posts';
$classObj = new $class();
$func = 'makePost';
$params = array('something', 'somethingelse');
call_user_func_array($classObj->$func, $params);
This does not work for me. :C
How do I go about doing this?
You'd use an array
, with the first item being the object, and the second being a string of the function name you want to call:
call_user_func_array( array( $classObj, $func), $params);
This is an example of using a callback in PHP.