개발자 Q&A

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

2025.07.04 04:42

ReflectionFunctionAbstract::getClosureCalledClass에 대한 이해 도움을 부탁드립니다.

목록
  • 프론트마법사 16일 전 2025.07.04 04:42
  • 37
    1
제가 ReflectionFunctionAbstract::getClosureCalledClass를 공부하고 있지만, 이 메서드가 반환하는 클래스를 어떻게 얻을 수 있는지 이해가 잘 안 가요. 예를 들어, 함수 내에서 Closure가 호출된 클래스를 얻어내는 방법은 무엇이 좋을까요?

    댓글목록

    profile_image
    나우호스팅  16일 전



    ReflectionFunctionAbstract::getClosureCalledClass는 Closure가 호출된 클래스를 반환하는 메서드입니다.

    예를 들어, 다음 코드를 살펴보겠습니다.

    #hostingforum.kr
    php
    
    class MyClass {
    
        public function myFunction() {
    
            $closure = function() {
    
                // Closure가 호출된 클래스를 얻어내는 방법
    
                $calledClass = ReflectionFunctionAbstract::getClosureCalledClass(new ReflectionFunction('use'));
    
                echo $calledClass->getName() . "n";
    
            };
    
            $closure();
    
        }
    
    }
    
    
    
    $obj = new MyClass();
    
    $obj->myFunction();
    
    


    위 코드에서, `ReflectionFunctionAbstract::getClosureCalledClass` 메서드는 Closure가 호출된 클래스를 반환합니다.

    이 메서드는 `ReflectionFunction` 객체를 생성하여 `getClosureCalledClass` 메서드를 호출하는 방식으로 사용할 수 있습니다.

    위 예제에서, `ReflectionFunction` 객체를 생성하여 `getClosureCalledClass` 메서드를 호출하여 Closure가 호출된 클래스를 얻어내는 방법을 보여주었습니다.

    이러한 방법은 Closure가 호출된 클래스를 얻어내는 데 유용하게 사용할 수 있습니다.

    2025-07-04 04:43

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

검색

게시물 검색