(PHP 8 >= 8.1.0)
ReflectionFunctionAbstract::getClosureUsedVariables — 返回 Closure 中使用的变量的数组
此函数没有参数。
示例 #1 ReflectionFunctionAbstract::getClosureUsedVariables() 示例
<?php
$one = 1;
$two = 2;
$function = function() use ($one, $two) {
static $three = 3;
};
$reflector = new ReflectionFunction($function);
var_dump($reflector->getClosureUsedVariables());
?>以上示例将输出类似以下内容
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}