Working on a new MVC Application Framework i use this method to check how many arguments are required before calling the sub method!
Example
<?php
$this->method_args_count = $this->CReflection
->getMethod($Route->getMethod())
->getNumberOfParameters();
//Maybe be 5 but if uri is /controller/method/single_param/ we only of 1
$this->params = $Route->getParams(); //0 in some cases
if($this->method_args_count > count($this->params))
{
$this->difference = ($this->method_args_count - count($this->params));
for($i=0;$i<=$this->difference;$i++)
{
$this->params[] = false;
}
}
//Call the method with correct amount of params
// but as false for params that have not been passed!
call_user_func_array(array(new $this->obj,$Route->getMethod()),$this->params);
?>
ReflectionFunctionAbstract::getNumberOfParameters
(PHP 5 >= 5.0.3)
ReflectionFunctionAbstract::getNumberOfParameters — دریافت تعداد پارامتر
Description
public int ReflectionFunctionAbstract::getNumberOfParameters
( void
)
دریافت تعداد پارامترهای تعریف شده تابع اختیاری و مورد نیاز.
Warning
This function is currently not documented; only its argument list is available.
Parameters
This function has no parameters.
Return Values
تعداد پارامترها.
See Also
- ReflectionFunctionAbstract::getNumberOfRequiredParameters() - دریافت تعداد پارامترهای مورد نیاز
Robert Pitt ( LitePHP ) ¶
3 years ago
