
ReflectionClass::getMethod 함수는 클래스의 메소드를 리플렉션하여 반환하는 함수입니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('클래스명');
$method = $reflectionClass->getMethod('메소드명');
getMethod 함수를 사용하여 메소드의 반환 타입을 확인할 수 있습니다.
#hostingforum.kr
php
$reflectionMethod = $reflectionClass->getMethod('메소드명');
$reflectionMethod->getReturnType();
getReturnType 함수는 메소드의 반환 타입을 반환합니다. 반환 타입이 없다면 NULL을 반환합니다.
#hostingforum.kr
php
if ($reflectionMethod->getReturnType() === '타입') {
// 타입이 맞는 경우
} else {
// 타입이 맞지 않는 경우
}
또한, getReturnType 함수는 PHP 7.0 이상에서만 사용할 수 있습니다. PHP 5.x에서는 사용할 수 없습니다.
#hostingforum.kr
php
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
// PHP 7.0 이상인 경우
} else {
// PHP 5.x인 경우
}
2025-08-07 12:06