
ReflectionParameter::isPromoted 메소드는 PHP 7.1.0 이상에서 사용할 수 있는 메소드입니다. 이 메소드는 매개변수가 암시적 타입_promoted_되는지 여부를 확인합니다.
이 메소드는 다음 상황에서 true를 반환합니다.
- 매개변수가 암시적 타입_promoted_되는 경우
- 매개변수가 타입_promoted_되지 않은 경우
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
function test(array $array, string $string) {
// ...
}
$reflectionMethod = new ReflectionMethod('test');
$reflectionParameter = $reflectionMethod->getParameters()[0];
var_dump($reflectionParameter->isPromoted); // bool(true)
위 코드에서, 매개변수 $array는 암시적 타입_promoted_되는 경우이므로, ReflectionParameter::isPromoted 메소드는 true를 반환합니다.
반면에, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
function test(array $array) {
// ...
}
$reflectionMethod = new ReflectionMethod('test');
$reflectionParameter = $reflectionMethod->getParameters()[0];
var_dump($reflectionParameter->isPromoted); // bool(false)
위 코드에서, 매개변수 $array는 암시적 타입_promoted_되지 않은 경우이므로, ReflectionParameter::isPromoted 메소드는 false를 반환합니다.
이 메소드는 다음과 같은 상황에서 사용할 수 있습니다.
- 타입_promoted_되는 매개변수의 존재 여부를 확인할 때
- 암시적 타입_promoted_되는 매개변수의 타입을 확인할 때
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
function test(array $array, string $string) {
if ($reflectionParameter->isPromoted) {
// 암시적 타입_promoted_되는 매개변수인 $array의 타입을 확인합니다.
}
}
$reflectionMethod = new ReflectionMethod('test');
$reflectionParameter = $reflectionMethod->getParameters()[0];
위 코드에서, ReflectionParameter::isPromoted 메소드는 암시적 타입_promoted_되는 매개변수의 존재 여부를 확인합니다.
2025-06-22 03:41