xref: /php-src/ext/reflection/tests/gh10623.phpt (revision ae164716)
1--TEST--
2GH-10623 (ReflectionFunction::getClosureUsedVariables() returns empty array in presence of variadic arguments)
3--FILE--
4<?php
5
6$data1 = 1;
7$data2 = 2;
8$data3 = 3;
9
10$closure = function($var) use($data1) {};
11var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
12
13$closure = function($var, ...$variadic) {};
14var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
15
16$closure = function($var, ...$variadic) use($data1) {};
17var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
18
19$closure = function($var, ...$variadic) use($data1, $data2, $data3) {};
20var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
21
22$closure = function(...$variadic) use($data1) {};
23var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
24
25$closure = function($var, $var2, ...$variadic) {};
26var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
27
28$closure = function($var, $var2, $var3, ...$variadic) use($data1, $data2, $data3) {};
29var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
30
31?>
32--EXPECT--
33array(1) {
34  ["data1"]=>
35  int(1)
36}
37array(0) {
38}
39array(1) {
40  ["data1"]=>
41  int(1)
42}
43array(3) {
44  ["data1"]=>
45  int(1)
46  ["data2"]=>
47  int(2)
48  ["data3"]=>
49  int(3)
50}
51array(1) {
52  ["data1"]=>
53  int(1)
54}
55array(0) {
56}
57array(3) {
58  ["data1"]=>
59  int(1)
60  ["data2"]=>
61  int(2)
62  ["data3"]=>
63  int(3)
64}
65