
ReflectionFunctionAbstract::hasTentativeReturnType 메서드는 PHP 7.0 이상에서 사용할 수 있는 기능입니다. 이 메서드는 함수의 반환 타입이 tentative return type인 경우 true를 반환합니다.
tentative return type이란, 함수의 반환 타입이 명시적으로 지정되지 않은 경우, 타입 힌트를 사용하여 반환 타입을 추론하는 것을 말합니다. 예를 들어, 다음 함수는 tentative return type을 사용합니다.
#hostingforum.kr
php
function foo(): mixed {
return 'hello';
}
이 함수의 반환 타입은 mixed입니다. 하지만, 실제로 반환되는 값은 string이므로, PHP는 이 함수의 반환 타입을 string으로 추론할 수 있습니다.
이러한 경우, ReflectionFunctionAbstract::hasTentativeReturnType 메서드는 true를 반환합니다.
#hostingforum.kr
php
$reflection = new ReflectionFunction('foo');
echo $reflection->hasTentativeReturnType(); // true
반환 타입이 명시적으로 지정된 경우, tentative return type이 아니므로, 이 메서드는 false를 반환합니다.
#hostingforum.kr
php
function foo(): string {
return 'hello';
}
$reflection = new ReflectionFunction('foo');
echo $reflection->hasTentativeReturnType(); // false
이 메서드는 함수의 반환 타입이 tentative return type인 경우에만 true를 반환하므로, 함수의 반환 타입을 추론하는 데 사용할 수 있습니다.
2025-06-25 19:12