Voting

: max(two, zero)?
(Example: nine)

The Note You're Voting On

cesar at magic3w dot com
9 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.

<?php

class 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 numbers
echo 'Test: ' . $r->getNumberOfRequiredParameters()); //Output: 2
echo 'Test2: ' . $r->getNumberOfRequiredParameters()); //Output: 2

?>

<< Back to user notes page

To Top