ReflectionFunctionAbstract::getNumberOfRequiredParameters

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

ReflectionFunctionAbstract::getNumberOfRequiredParametersObtém o número de parâmetros necessários

Descrição

public ReflectionFunctionAbstract::getNumberOfRequiredParameters(): int

Obtém o número de parâmetros necessários que uma função define.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

O número de parâmetros necessários.

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 2 notes

up
6
cesar at magic3w dot com
10 years ago
It's interesting to note that this function will treat optional parameters that come before a required parameter as required too. This is good since it allows you to verify that the function will be receiving enough parameters for the it to work, regardless where they are located.<?phpclass MyTest() {    public function test($a = null, $b) {}    public function test2($a = null, $b, $c = null) {}}//Create the reflection$r  = new \ReflectionMethod('MyTest', 'test');$r2 = new \ReflectionMethod('MyTest', 'test2');//Verify the numbersecho 'Test: ' . $r->getNumberOfRequiredParameters()); //Output: 2echo 'Test2: ' . $r->getNumberOfRequiredParameters()); //Output: 2?>
up
4
sebastian at sebastian-eiweleit dot de
11 years ago
<?phpnamespace ExampleWorld;// The Classclass helloWorld {    /* Method with two required arguments */    public function requiredTwoArguments ( $var1, $var2 ) {        // Some code ...    }    /* Method with two arguments, but just one is required */    public function requiredOneArgument ( $var1, $var2 = false ) {        // Some code ...    }}$r = new \ReflectionMethod ( 'ExampleWorld\helloWorld', 'requiredTwoArguments' );echo $r->getNumberOfRequiredParameters ();$r = new \ReflectionMethod ( 'ExampleWorld\helloWorld', 'requiredOneArgument' );echo $r->getNumberOfRequiredParameters ();// Output: 2 1
To Top