I don't believe you can pass that just as is, but that doesn't mean it can't be achieved. You could write a small function that will parse the input into values you can use to call the desired function. Something like this
<?php
// I've commented your include because it doesn't benefit this example
//include 'class/class.sample.php';
$sampleObj = new sample();
//$function = $_POST['query']; //ex empid('1');
// set input hardcoded for the benefit of this example
$output = fetchFunction("empid('1','2','3')");
call_user_func_array(array($sampleObj, $output['function']), $output['parameters']);
/**
* Use this function to parse input like "empid('1','2')"
* to array('function'=>'empid',parameters=>array(1,2))
* This can be used in a call_user_func_array
*
* @param $input
* @return array
*/
function fetchFunction($input){
// match inside () to get the parameters
preg_match('/(?<=\()(.+)(?=\))/is', $input, $parameters);
return array(
'parameters' => explode(',', str_replace(array('\'','"'),'',$parameters[0])),
'function' => substr($input,0,strpos($input,'('))
);
}
class sample{
public function empid($id){
print_r(func_get_args());
}
}
I've added a dummy class to show the output, and didn't include any check for existing functions for instance (possible with something like method_exists
). You'll need to change that to work with your own class setup and functions.