I have a class which has many methods. I have created one another php which creates an object of this class. Now I get a method name of that class from POST data. I want to call the respective method of that class using the object of that class and the method name I got from POST data.
I want something like this ::
//php class file ABC.php
class ABC
{
public function sayHi($input)
{
return "Hi " . $input;
}
public function sayHello($input)
{
return "Hello " . $input;
}
}
//another php named test.php
$obj = new ABC();
$methodName = $_REQUEST['takeAction']; //$methodName = 'sayHi' or 'sayHello'
$val = $obj->$methodName("Naresh"); //I don't know what should be here, in fact this is my question
echo "output : " . $val;
I guess this is pretty simple to understand what I want. Let me know if you know. Thanks in advance
Regards,
Naresh