(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) }