Is there a way to figure out how many parameters a defined method expects from outside of the method? (PHP) -


itemprop = "text">

After I create a MVC framework, through which the requested operation passes a url parameter after the "action" parameter Method standards of action I am working

So if the URL is:.

  host / controller_name / ACTION_NAME / param1 / param2   

The following takes place (simplified by the course):

  $ Request_controller = new controller_name (); Call_user_func_array (Array ($ request_controller, ACTION_NAME), array (param1, param2);.   

The problem is in error reporting is requested with the wrong number of a URL parameter (action two Expected standards, but the URL is only a parameter, I get a warning message, then the havoc).

Since this is an exception, instead of a procedural error, I can not try / in any way Can I hold it, can I? Is it Is there any way to check the number of parameters required for the action method before trying to bring it? Or am I completely attacking it differently?

Edit (solution) $ action_method_relfection = New ReflectionMethod ($ request_controller, $ request_action); if (count $ ($ path_variables) & $; action_method_relfection- & gt; getNumberOfRequiredParameters () || Count ($ path_variables) & Gt; $ action_method_relfection-> getNumberOfParameters ()) {// If not, then the 404 error is self: redirect_to_404 ();}

I think, you can figure out how many parameters each method accepts, using some combination,


  • Your solution for another solution will be considered only one - and always the one-parameter: an array, in which any possible Items may be included.

    In this way, you always pass a parameter, all the methods always expect a parameter; No more warnings / errors now

Comments