개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.23 20:35

ReflectionParameter::isPromoted 관련 질문내용

목록
  • 네트워크마법사 6시간 전 2025.04.23 20:35 새글
  • 3
    1
ReflectionParameter::isPromoted 이해에 도움을 요청합니다.

제발 도와주세요. ReflectionParameter::isPromoted 메서드는 어떤 경우에 true를 반환하는지 알려주세요.

예를 들어, 아래와 같은 코드가 있을 때, ReflectionParameter::isPromoted($param)에서 $param이 boolean 타입일 때 true를 반환하는지 궁금합니다.

php

function test($param) {

    // 코드...

}



$reflectionMethod = new ReflectionMethod('클래스명', 'test');

$reflectionParameter = $reflectionMethod->getParameters()[0];

var_dump($reflectionParameter->isPromoted($param));



이런 경우 ReflectionParameter::isPromoted($param)에서 $param이 boolean 타입일 때 true를 반환하는지 알려주세요.

    댓글목록

    profile_image
    나우호스팅  6시간 전



    ReflectionParameter::isPromoted 메서드는 PHP 7.1 이상에서 사용할 수 있습니다. 이 메서드는 인자로 전달된 변수가 함수의 매개변수에 의해 암시적으로提升되는지 여부를 반환합니다.

    예를 들어, 아래와 같은 코드가 있을 때, ReflectionParameter::isPromoted($param)에서 $param이 boolean 타입일 때 true를 반환하는지 궁금합니다.

    #hostingforum.kr
    php
    
    function test($param) {
    
        // 코드...
    
    }
    
    
    
    $reflectionMethod = new ReflectionMethod('클래스명', 'test');
    
    $reflectionParameter = $reflectionMethod->getParameters()[0];
    
    var_dump($reflectionParameter->isPromoted(true)); // true
    
    var_dump($reflectionParameter->isPromoted(false)); // false
    
    


    위의 예제에서, $param이 boolean 타입일 때 true를 반환하는 이유는 PHP에서 boolean 타입은 integer 타입의 서브셋으로 간주되기 때문입니다. 따라서, boolean 타입의 변수가 함수의 매개변수에 의해 암시적으로提升되는 경우 true를 반환합니다.

    반면, integer 타입의 변수나 string 타입의 변수는 암시적으로提升되지 않기 때문에 false를 반환합니다.

    #hostingforum.kr
    php
    
    var_dump($reflectionParameter->isPromoted(1)); // false
    
    var_dump($reflectionParameter->isPromoted('hello')); // false
    
    

    2025-04-23 20:36

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 13,820건 / 1 페이지

검색

게시물 검색