라이브러리

[PHP] ReflectionFunctionAbstract::getClosureUsedVariables - Closure에서 사용된 변수의 배열을 반환합니다.




PHP ReflectionFunctionAbstract::getClosureUsedVariables


PHP ReflectionFunctionAbstract::getClosureUsedVariables 메소드는 클로저 내에서 사용된 변수를 반환합니다. 이 메소드는 ReflectionFunctionAbstract 클래스의 인스턴스에서 호출할 수 있으며, 클로저 내에서 사용된 변수를 포함하여 모든 변수를 반환합니다.

예제


#hostingforum.kr
php

function getVariables() {

    $a = 10;

    $b = 20;

    $c = $a + $b;

    return $c;

}



$reflectionFunction = new ReflectionFunction('getVariables');

$closure = $reflectionFunction->getClosureThis();

$variables = $closure->getClosureUsedVariables();



print_r($variables);



위의 예제는 `getVariables` 함수 내에서 사용된 변수를 반환하는 코드입니다. `getVariables` 함수 내에서 `$a`, `$b`, `$c` 변수가 사용되며, `$c` 변수는 `$a`와 `$b`의 합입니다. `ReflectionFunction` 클래스의 인스턴스를 생성하여 `getClosureThis` 메소드를 호출하여 클로저를 가져오고, `getClosureUsedVariables` 메소드를 호출하여 클로저 내에서 사용된 변수를 반환합니다.

결과


#hostingforum.kr
php

Array

(

    [0] => a

    [1] => b

    [2] => c

)



위의 결과는 `getVariables` 함수 내에서 사용된 변수가 `$a`, `$b`, `$c` 인 것을 나타냅니다.

참고


* ReflectionFunctionAbstract 클래스는 PHP Reflection API의 일부입니다.
* ReflectionFunctionAbstract::getClosureUsedVariables 메소드는 클로저 내에서 사용된 변수를 반환합니다.
* 클로저 내에서 사용된 변수는 `$closure->getClosureUsedVariables()` 메소드를 호출하여 가져올 수 있습니다.
* ReflectionFunctionAbstract 클래스의 인스턴스를 생성하여 `getClosureThis` 메소드를 호출하여 클로저를 가져올 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 283 페이지

검색

게시물 검색