라이브러리
[PHP] ReflectionGenerator::getFunction - 생성기의 함수 이름을 가져옵니다.
ReflectionGenerator::getFunction
PHP Reflection API는 PHP 코드를 분석하고 정보를 얻는 데 사용되는 강력한 도구입니다. ReflectionGenerator::getFunction은 ReflectionGenerator 객체에서 함수 정보를 얻는 데 사용되는 메서드입니다.
# ReflectionGenerator
ReflectionGenerator는 Reflection API의 일부로, PHP 코드를 실행하는 동안 생성되는 Generator 객체를 나타냅니다. Generator는 함수를 호출할 때마다 실행을 중단하고, 다음 실행을 위해 저장된 상태를 반환하는 특수한 형태의 함수입니다.
# ReflectionGenerator::getFunction
ReflectionGenerator::getFunction 메서드는 ReflectionGenerator 객체에서 함수 정보를 얻는 데 사용됩니다. 이 메서드는 ReflectionFunction 객체를 반환합니다. ReflectionFunction 객체는 함수의 이름, 반환 타입, 매개변수 정보, 그리고 함수의 소스 코드를 포함하는 객체입니다.
# 예제
다음 예제는 ReflectionGenerator::getFunction 메서드를 사용하는 방법을 보여줍니다.
#hostingforum.kr
php
<?php
function myGenerator() {
yield 1;
yield 2;
yield 3;
}
$generator = myGenerator();
$reflectionGenerator = new ReflectionGenerator($generator);
$reflectionFunction = $reflectionGenerator->getFunction();
print($reflectionFunction->getName() . "
"); // myGenerator
print($reflectionFunction->getReturnType() . "
"); // void
print_r($reflectionFunction->getParameters()); // Array ( [0] => ReflectionParameter Object ( [name] => current [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) [1] => ReflectionParameter Object ( [name] => key [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) [2] => ReflectionParameter Object ( [name] => value [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) )
?>
# 결과
이 예제의 결과는 다음과 같습니다.
#hostingforum.kr
myGenerator
void
Array ( [0] => ReflectionParameter Object ( [name] => current [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) [1] => ReflectionParameter Object ( [name] => key [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) [2] => ReflectionParameter Object ( [name] => value [isPassedByReference] => [isOptional] => [isVariadic] => [defaultValue] => ) )
# 결론
ReflectionGenerator::getFunction 메서드는 ReflectionGenerator 객체에서 함수 정보를 얻는 데 사용됩니다. 이 메서드는 ReflectionFunction 객체를 반환하며, 함수의 이름, 반환 타입, 매개변수 정보, 그리고 함수의 소스 코드를 포함하는 객체입니다. 이 메서드는 PHP Reflection API의 일부로, PHP 코드를 분석하고 정보를 얻는 데 사용됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.