라이브러리
[PHP] ReflectionFunctionAbstract::getTentativeReturnType - 함수와 연관된 임시 반환 유형을 반환합니다.
PHP ReflectionFunctionAbstract::getTentativeReturnType은 PHP 8.0 버전부터 지원하는 기능입니다. 이 기능은 함수의 반환 타입을 추측하는 데 사용됩니다.
ReflectionFunctionAbstract::getTentativeReturnType
ReflectionFunctionAbstract::getTentativeReturnType은 함수의 반환 타입을 추측하는 데 사용됩니다. 이 기능은 PHP 8.0 버전부터 지원하는 기능입니다.
# 예제
#hostingforum.kr
php
<?php
function getTentativeReturnTypeExample(): void {
$reflectionFunction = new ReflectionFunction('getTentativeReturnTypeExample');
$tentativeReturnType = $reflectionFunction->getTentativeReturnType();
echo "getTentativeReturnTypeExample 함수의 추측 반환 타입: $tentativeReturnType
";
}
function getTentativeReturnTypeExample(): string {
return "Hello, World!";
}
getTentativeReturnTypeExample();
?>
위의 예제에서 `getTentativeReturnTypeExample` 함수는 `string` 타입을 반환합니다. 그러나 `ReflectionFunctionAbstract::getTentativeReturnType` 메서드는 함수의 반환 타입을 추측하기 때문에 `void` 타입을 반환합니다.
# 예제 2
#hostingforum.kr
php
<?php
function getTentativeReturnTypeExample(): string {
return "Hello, World!";
}
$reflectionFunction = new ReflectionFunction('getTentativeReturnTypeExample');
$tentativeReturnType = $reflectionFunction->getTentativeReturnType();
echo "getTentativeReturnTypeExample 함수의 추측 반환 타입: $tentativeReturnType
";
?>
위의 예제에서 `getTentativeReturnTypeExample` 함수는 `string` 타입을 반환합니다. 이 경우 `ReflectionFunctionAbstract::getTentativeReturnType` 메서드는 함수의 반환 타입을 정확하게 추측하여 `string` 타입을 반환합니다.
참고
- PHP 8.0 버전부터 지원하는 기능입니다.
- 함수의 반환 타입을 추측하는 데 사용됩니다.
- 함수의 반환 타입이 명시되지 않은 경우 `void` 타입을 반환합니다.
- 함수의 반환 타입이 명시된 경우 정확한 반환 타입을 반환합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.