PHP - Manual: ReflectionFunctionAbstract::getClosureUsedVariables
2024-12-22
(PHP 8 >= 8.1.0)
ReflectionFunctionAbstract::getClosureUsedVariables — Returns an array of the used variables in the Closure
Returns an array of the used variables in the Closure.
此函数没有参数。
Returns an array of the used variables in the Closure.
示例 #1 ReflectionFunctionAbstract::getClosureUsedVariables() example
<?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) }
官方地址:https://www.php.net/manual/en/reflectionfunctionabstract.getclosureusedvariables.php