PHP: Hypertext Preprocessor (original) (raw)

ReflectionFunctionAbstract::getNumberOfParameters

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

ReflectionFunctionAbstract::getNumberOfParameters — Gets number of parameters

Description

public ReflectionFunctionAbstract::getNumberOfParameters(): int

Parameters

This function has no parameters.

Return Values

The number of parameters.

See Also

Found A Problem?

Robert Pitt ( LitePHP )

15 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

this−>methodargscount=this->method_args_count = this>methodargscount=this->CReflection ->getMethod($Route->getMethod()) ->getNumberOfParameters(); //Maybe be 5 but if uri is /controller/method/single_param/ we only of 1 this−>params=this->params = this>params=Route->getParams(); //0 in some casesif($this->method_args_count > count($this->params)) { this−>difference=(this->difference = (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,this->obj,this>obj,Route->getMethod()),$this->params); ?>

`

8ctopus

4 years ago

$reflection = new ReflectionFunction('implode'); echo $reflection->getNumberOfParameters();