PHP Conference Japan 2024

ReflectionFunctionAbstract::getClosureUsedVariables

(PHP 8 >= 8.1.0)

ReflectionFunctionAbstract::getClosureUsedVariables傳回 Closure 中使用的變數陣列

說明

public ReflectionFunctionAbstract::getClosureUsedVariables(): 陣列

傳回 Closure 中使用的變數 陣列

參數

此函式沒有參數。

回傳值

傳回 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)
}

另請參閱

新增註記

使用者提供的註記

此頁面沒有使用者提供的註記。
To Top