Skip to content

ReflectionFunction::getClosureUsedVariables() returns empty array in presence of variadic arguments #10623

Closed
@fabio-ivona

Description

@fabio-ivona

Description

It seems that when using a ReflectionFunction method getClosureUsedVariables() to retrieve its use variables, when the closure has a variadic argument, getClosureUsedVariables() returns an empty array

it can be reproduced (both in PHP8.1 and PHP8.2) by running this simple snipped

$data = 1;
$closure = function($var) use($data){};
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());

$closure = function($var, ...$variadic) use($data){};
var_dump((new ReflectionFunction($closure))->getClosureUsedVariables());

Resulted in this output:

array(1) {
  ["data"] => int(1)
}
array(0) {
}

But I expected this output instead:

array(1) {
  ["data"] => int(1)
}
array(0) {
  ["data"] => int(1)
}

PHP Version

PHP 8.2.2 (also in PHP 8.1.15 as well)

Operating System

tested in Ubuntu 20.04, 21.04 and alpine

Example snippet

https://onlinephp.io/c/1fd54

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions