Skip to content

Commit 2f4ba1b

Browse files
committedFeb 19, 2023
Merge branch 'PHP-8.1' into PHP-8.2
2 parents 7d22978 + ae16471 commit 2f4ba1b

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
 

‎ext/reflection/php_reflection.c

+4
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,10 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureUsedVariables)
17531753
}
17541754

17551755
zend_op *opline = ops->opcodes + ops->num_args;
1756+
if (ops->fn_flags & ZEND_ACC_VARIADIC) {
1757+
ZEND_ASSERT(opline->opcode == ZEND_RECV_VARIADIC);
1758+
opline++;
1759+
}
17561760

17571761
for (; opline->opcode == ZEND_BIND_STATIC; opline++) {
17581762
if (!(opline->extended_value & (ZEND_BIND_IMPLICIT|ZEND_BIND_EXPLICIT))) {

‎ext/reflection/tests/gh10623.phpt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
GH-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) {};
11+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
12+
13+
$closure = function($var, ...$variadic) {};
14+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
15+
16+
$closure = function($var, ...$variadic) use($data1) {};
17+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
18+
19+
$closure = function($var, ...$variadic) use($data1, $data2, $data3) {};
20+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
21+
22+
$closure = function(...$variadic) use($data1) {};
23+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
24+
25+
$closure = function($var, $var2, ...$variadic) {};
26+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
27+
28+
$closure = function($var, $var2, $var3, ...$variadic) use($data1, $data2, $data3) {};
29+
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());
30+
31+
?>
32+
--EXPECT--
33+
array(1) {
34+
["data1"]=>
35+
int(1)
36+
}
37+
array(0) {
38+
}
39+
array(1) {
40+
["data1"]=>
41+
int(1)
42+
}
43+
array(3) {
44+
["data1"]=>
45+
int(1)
46+
["data2"]=>
47+
int(2)
48+
["data3"]=>
49+
int(3)
50+
}
51+
array(1) {
52+
["data1"]=>
53+
int(1)
54+
}
55+
array(0) {
56+
}
57+
array(3) {
58+
["data1"]=>
59+
int(1)
60+
["data2"]=>
61+
int(2)
62+
["data3"]=>
63+
int(3)
64+
}

0 commit comments

Comments
 (0)
Please sign in to comment.