xref: /PHP-7.2/ext/reflection/tests/025.phpt (revision 17ccbeec)
1--TEST--
2ReflectionFunction basic tests
3--SKIPIF--
4<?php extension_loaded('reflection') or die('skip'); ?>
5--INI--
6opcache.save_comments=1
7--FILE--
8<?php
9
10/**
11hoho
12*/
13function test ($a, $b = 1, $c = "") {
14	static $var = 1;
15}
16
17$func = new ReflectionFunction("test");
18
19var_dump($func->export("test"));
20echo "--getName--\n";
21var_dump($func->getName());
22echo "--isInternal--\n";
23var_dump($func->isInternal());
24echo "--isUserDefined--\n";
25var_dump($func->isUserDefined());
26echo "--getFilename--\n";
27var_dump($func->getFilename());
28echo "--getStartline--\n";
29var_dump($func->getStartline());
30echo "--getEndline--\n";
31var_dump($func->getEndline());
32echo "--getDocComment--\n";
33var_dump($func->getDocComment());
34echo "--getStaticVariables--\n";
35var_dump($func->getStaticVariables());
36echo "--invoke--\n";
37var_dump($func->invoke(array(1,2,3)));
38echo "--invokeArgs--\n";
39var_dump($func->invokeArgs(array(1,2,3)));
40echo "--returnsReference--\n";
41var_dump($func->returnsReference());
42echo "--getParameters--\n";
43var_dump($func->getParameters());
44echo "--getNumberOfParameters--\n";
45var_dump($func->getNumberOfParameters());
46echo "--getNumberOfRequiredParameters--\n";
47var_dump($func->getNumberOfRequiredParameters());
48
49echo "Done\n";
50
51?>
52--EXPECTF--
53/**
54hoho
55*/
56Function [ <user> function test ] {
57  @@ %s 6 - 8
58
59  - Parameters [3] {
60    Parameter #0 [ <required> $a ]
61    Parameter #1 [ <optional> $b = 1 ]
62    Parameter #2 [ <optional> $c = '' ]
63  }
64}
65
66NULL
67--getName--
68string(4) "test"
69--isInternal--
70bool(false)
71--isUserDefined--
72bool(true)
73--getFilename--
74string(%d) "%s025.php"
75--getStartline--
76int(6)
77--getEndline--
78int(8)
79--getDocComment--
80string(%d) "/**
81hoho
82*/"
83--getStaticVariables--
84array(1) {
85  ["var"]=>
86  int(1)
87}
88--invoke--
89NULL
90--invokeArgs--
91NULL
92--returnsReference--
93bool(false)
94--getParameters--
95array(3) {
96  [0]=>
97  object(ReflectionParameter)#2 (1) {
98    ["name"]=>
99    string(1) "a"
100  }
101  [1]=>
102  object(ReflectionParameter)#3 (1) {
103    ["name"]=>
104    string(1) "b"
105  }
106  [2]=>
107  object(ReflectionParameter)#4 (1) {
108    ["name"]=>
109    string(1) "c"
110  }
111}
112--getNumberOfParameters--
113int(3)
114--getNumberOfRequiredParameters--
115int(1)
116Done
117