개발자 Q&A

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

2025.07.20 04:12

ReflectionFunction::getClosure 이해에 필요한 도움을 부탁드립니다.

목록
  • JetpackCompose마… 3일 전 2025.07.20 04:12
  • 34
    1
제시된 코드에서 ReflectionFunction::getClosure의 결과가 null인 이유를 알려주세요.
php

function test() {

    $reflection = new ReflectionFunction('test');

    $closure = $reflection->getClosure();

    var_dump($reflection->getClosure());

}


위 코드에서 `$reflection->getClosure()`의 결과가 null인 이유를 알려주세요.

    댓글목록

    profile_image
    나우호스팅  3일 전



    ReflectionFunction::getClosure() 메소드는 함수의 클로저를 반환합니다. 그러나 클로저가 없을 경우 null을 반환합니다.

    위 코드에서 test() 함수는 클로저를 사용하지 않았기 때문에 ReflectionFunction::getClosure()의 결과가 null입니다.

    클로저를 사용하려면 함수에 클로저를 선언해야 합니다. 예를 들어, 다음과 같이 사용할 수 있습니다.

    #hostingforum.kr
    php
    
    function test() {
    
        $closure = function() {
    
            echo "클로저가 호출되었습니다.";
    
        };
    
        return $closure;
    
    }
    
    
    
    $reflection = new ReflectionFunction('test');
    
    $closure = $reflection->getClosure();
    
    var_dump($closure);
    
    


    이 코드에서는 test() 함수에 클로저를 선언하고, ReflectionFunction::getClosure()를 사용하여 클로저를 반환합니다.

    2025-07-20 04:13

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

검색

게시물 검색