Reputation: 238
Im working lately on a custom mvc for php, and one of the question was really bothered me: Ive got the controller class, and i want to check if a certain function of the class getting arguments, and if not, return false.
is there any method to do it? cause i searched in php.net and google and didn't find anything.... thanx!
Upvotes: 2
Views: 553
Reputation: 13594
Use function func_get_args
function sum(){
$s=0;
foreach(func_get_args() as $a) $s+= is_numeric($a)?$a:0;
return $s;
};
print sum(1,2,3,4,5,6); // 21
Upvotes: 0
Reputation: 13257
Use reflection:
$reflection = new ReflectionMethod ($class_name, $method_name);
$params = $r->getParameters();
$params
is now an array of ReflectionParameter objects
Upvotes: 2
Reputation: 20249
Have a look at func_get_args
You can use it inside the method in your controller to get the list of all arguments passed to the method.
You also have func_num_args
that will just give you the number of arguments passed to your method.
Upvotes: 2