PHP 8.3.4 Released!

ReflectionFunctionAbstract::getClosureUsedVariables

(PHP 8 >= 8.1.0)

ReflectionFunctionAbstract::getClosureUsedVariablesクロージャ内で使われている変数の配列を返す

説明

public ReflectionFunctionAbstract::getClosureUsedVariables(): array

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

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top