1--TEST--
2ReflectionParameter class - isOptional, isDefaultValueAvailable and getDefaultValue methods.
3--CREDITS--
4Robin Fernandes <robinf@php.net>
5Steve Seear <stevseea@php.net>
6--FILE--
7<?php
8
9class ReflectTestClass {
10    public static function staticMethod($paramOne, $anotherParam = "bob",
11                                        &$thirdParam = "jack", $arrayParam = array('one')) {
12        echo "hello from test\n";
13        echo "third is $thirdParam\n";
14        return ++$theIncrement;
15    }
16
17}
18
19$jane = "jane";
20ReflectTestClass::staticMethod("bob", "jack");
21
22$refMethod = new ReflectionMethod('ReflectTestClass', 'staticMethod');
23$refParameters = $refMethod->getParameters();
24
25echo "parameter names from staticMethod method:\n\n";
26foreach($refParameters as $parameter) {
27    var_dump($parameter);
28    if($parameter->isOptional()) {
29      echo "this parameter is optional\n";
30    } else {
31      echo "this parameter is not optional\n";
32    }
33
34    if($parameter->isDefaultValueAvailable()) {
35      echo "this parameter has a default value\n";
36    } else {
37      echo "this parameter has no default value\n";
38    }
39
40    /*
41    $val = 0;
42    try {
43        $val = $parameter->getDefaultValue();
44        var_dump($val);
45    } catch (ReflectionException $e) {
46        print $e->getMessage();
47        echo "\n";
48    }
49    */
50
51    echo "\n";
52}
53
54?>
55--EXPECTF--
56hello from test
57third is jack
58
59Warning: Undefined variable $theIncrement in %s on line %d
60parameter names from staticMethod method:
61
62object(ReflectionParameter)#%d (1) {
63  ["name"]=>
64  string(8) "paramOne"
65}
66this parameter is not optional
67this parameter has no default value
68
69object(ReflectionParameter)#%d (1) {
70  ["name"]=>
71  string(12) "anotherParam"
72}
73this parameter is optional
74this parameter has a default value
75
76object(ReflectionParameter)#%d (1) {
77  ["name"]=>
78  string(10) "thirdParam"
79}
80this parameter is optional
81this parameter has a default value
82
83object(ReflectionParameter)#%d (1) {
84  ["name"]=>
85  string(10) "arrayParam"
86}
87this parameter is optional
88this parameter has a default value
89