ReflectionFunctionAbstract::getNumberOfParameters

(PHP 5 >= 5.0.3, PHP 7)

ReflectionFunctionAbstract::getNumberOfParametersGets number of parameters

설명

public int ReflectionFunctionAbstract::getNumberOfParameters ( void )

Get the number of parameters that a function defines, both optional and required.

Warning

이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.

인수

이 함수는 인수가 없습니다.

반환값

The number of parameters.

참고

add a note add a note

User Contributed Notes 2 notes

up
5
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);
?>
up
0
8ctopus
4 years ago
$reflection = new ReflectionFunction('implode');
echo $reflection->getNumberOfParameters();
To Top