How to find the standard PHP, do I need the arguments for the method call?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/code-flow.club/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
15 views
Writing your bike for the experience, routing is done as in CI:


CodeIgniter utilizes an approach based on segments of addresses:
www.your-site.com/news/article/my_article


The segments in the URL follow the architecture Model-view-Controller and, as a rule, are constructed thus:
www.your-site.com/class/function/arg


In the first segment describes the controller class is queried.

In the second segment is a reference to the function function or method you want to call.

In the third and following segments describe the variables that will be passed to this function.


In the CI method can look for example like this:


function hello ($name, $id) {

echo "\\$name = $name";

echo "

";

echo "$id";


}


Now the question is, in cases, if the url was not transferred to one of the arguments for the method, of course, an error occurs.

How to check how many arguments required to invoke the method? You need to check before you call, so func_num_args do not get to use.


Or perhaps there is another way out tell me? Advance very grateful.
by | 15 views

4 Answers

0 like 0 dislike
by
0 like 0 dislike
php.net/manual/en/book.reflection.php
\r
function test_function($param1, $param2 = NULL) { echo $param1; } $ref_function = new ReflectionFunction('test_function'); foreach($ref_function->getParameters() as $param) { var_dump($param->isOptional()); } var_dump($ref_function->getNumberOfRequiredParameters()); 

prints:
\rbool(false)
bool(true)
int(1)
\r
by
0 like 0 dislike
In my opinion it is better to catch errors at the function level, such as:
\r
\r
function my_action($param1 = null, $param2 = null) { if($param1 === null) { throw new Exception("); } } 
by
0 like 0 dislike
I was looking to see how CI done?
by

Related questions

0 like 0 dislike
1 answer
asked May 22, 2019 by SerafimArts
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 20, 2019 by phpcoder81
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
22,132 users