ReflectionFunctionAbstract::getNumberOfParameters
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
ReflectionFunctionAbstract::getNumberOfParameters — パラメータ数を取得する
説明
関数で定義されているパラメータの数を、必須と任意の両方を含めて取得します。
パラメータ
この関数にはパラメータはありません。
戻り値
パラメータの数を返します。
参考
- ReflectionFunctionAbstract::getNumberOfRequiredParameters() - 必須パラメータの数を取得する
- func_num_args() - 関数に渡された引数の数を返す
+add a note
User Contributed Notes 2 notes
Robert Pitt ( LitePHP ) ¶
14 years ago
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);
?>
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google