1--TEST--
2ReflectionParameter Check for parameter being optional
3--FILE--
4<?php
5
6class Test {
7    function func($x, $y = NULL){
8    }
9}
10
11
12$f = new ReflectionMethod('Test', 'func');
13var_dump($f->getNumberOfParameters());
14var_dump($f->getNumberOfRequiredParameters());
15
16$p = new ReflectionParameter(array('Test', 'func'), 'x');
17var_dump($p->isOptional());
18
19$p = new ReflectionParameter(array('Test', 'func'), 'y');
20var_dump($p->isOptional());
21
22try {
23    $p = new ReflectionParameter(array('Test', 'func'), 'z');
24    var_dump($p->isOptional());
25} catch (Exception $e) {
26    var_dump($e->getMessage());
27}
28try {
29    $p = new ReflectionParameter(array('Test', 'func'), -1);
30    var_dump($p->isOptional());
31} catch (\ValueError $e) {
32    var_dump($e->getMessage());
33}
34
35?>
36--EXPECT--
37int(2)
38int(1)
39bool(false)
40bool(true)
41string(54) "The parameter specified by its name could not be found"
42string(91) "ReflectionParameter::__construct(): Argument #2 ($param) must be greater than or equal to 0"
43