I’m looking for a way to determine the amount of parameters a function requires from outside of the function. “func_get_args” works only within a function, so it wont work. The purpose I have in mind is a request router that looks for class methods based on a url supplied, and then supplies the remaining arguments to the method as given by the url. But the method currently can be called even if an invalid number of parameters/arguments is supplied, leading to errors.
To be clear: by “outside of the function,” I mean outside of the function’s scope.
Good question. It turns out that you can check the number of arguments that a function accepts using PHP’s Reflection classes:
$refFunc = new ReflectionFunction('preg_replace'); echo $refFunc->getNumberOfParameters(); // Outputs: 5