개발자 Q&A

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

2025.04.28 19:07

ReflectionClass::getInterfaces()에 대한 질문

목록
  • 트랜잭션장인 1일 전 2025.04.28 19:07
  • 10
    1
제가 ReflectionClass::getInterfaces() 메서드에 대해 이해가 잘 안 가는 부분이 있습니다.

ReflectionClass::getInterfaces() 메서드는 클래스의 인터페이스를 반환합니다. 그러나 이 메서드는 인터페이스를 반환하는 대신, 인터페이스 이름을 반환하는 것처럼 보입니다.

아래 코드를 예시로 들어 보겠습니다.

php

class MyClass {

    public function myMethod() {}

}



interface MyInterface {

    public function myMethod();

}



class MyClassWithInterface extends MyClass implements MyInterface {}



$reflectionClass = new ReflectionClass('MyClassWithInterface');

$interfaces = $reflectionClass->getInterfaces();



print_r($interfaces);



위 코드를 실행한 결과는 다음과 같습니다.

```php
Array
(
[0] => ReflectionClass Object
(
[name] => MyInterface
[namespace] =>
[filename] =>
[filepath] =>
[lineno] =>
[nameWithoutNamespace] => MyInterface
[namespaceName] =>
[reflection] => ReflectionClass Object
(
[name] => MyInterface
[namespace] =>
[filename] =>
[filepath] =>
[lineno] =>
[nameWithoutNamespace] => MyInterface
[namespaceName] =>
[reflection] => ReflectionClass Object
(
[name] => MyInterface
[namespace] =>
[filename] =>
[filepath] =>
[lineno] =>
[nameWithoutNamespace] => MyInterface
[namespaceName] =>
[reflection] =>
)

[isUserDefined] => 1
[isInternal] =>
[isUserDefinedStatic] => 1
[isInternalStatic] =>
[isInstantiable] => 1
[isAbstract] =>
[isFinal] =>
[isCloneable] => 1
[isUnsettable] =>
[isSerialized] =>
)

[isUserDefined] => 1
[isInternal] =>
[isUserDefinedStatic] => 1
[isInternalStatic] =>
[isInstantiable] => 1
[is

    댓글목록

    profile_image
    나우호스팅  1일 전



    ReflectionClass::getInterfaces() 메서드는 클래스의 인터페이스를 반환합니다. 그러나 이 메서드는 인터페이스를 반환하는 대신, 인터페이스 이름을 반환하는 것처럼 보입니다.

    이유는 ReflectionClass::getInterfaces() 메서드는 ReflectionClass 객체를 반환하는 것이 아니라, 인터페이스 이름을 반환하는 것입니다.

    예를 들어, 클래스 MyClassWithInterface가 MyInterface 인터페이스를 구현하고 있다고 가정해 보겠습니다.

    #hostingforum.kr
    php
    
    class MyClassWithInterface extends MyClass implements MyInterface {}
    
    


    이 경우, ReflectionClass::getInterfaces() 메서드를 호출하면 MyInterface 인터페이스의 이름을 반환합니다.

    #hostingforum.kr
    php
    
    $reflectionClass = new ReflectionClass('MyClassWithInterface');
    
    $interfaces = $reflectionClass->getInterfaces();
    
    print_r($interfaces);
    
    


    결과는 다음과 같습니다.

    #hostingforum.kr
    php
    
    Array
    
    (
    
        [0] => ReflectionClass Object
    
            (
    
                [name] => MyInterface
    
                [namespace] => 
    
                [filename] => 
    
                [filepath] => 
    
                [lineno] => 
    
                [nameWithoutNamespace] => MyInterface
    
                [namespaceName] => 
    
                [reflection] => ReflectionClass Object
    
                    (
    
                        [name] => MyInterface
    
                        [namespace] => 
    
                        [filename] => 
    
                        [filepath] => 
    
                        [lineno] => 
    
                        [nameWithoutNamespace] => MyInterface
    
                        [namespaceName] => 
    
                        [reflection] => 
    
                    )
    
                [isUserDefined] => 1
    
                [isInternal] => 
    
                [isUserDefinedStatic] => 1
    
                [isInternalStatic] => 
    
                [isInstantiable] => 1
    
                [isAbstract] => 
    
                [isFinal] => 
    
                [isCloneable] => 1
    
                [isUnsettable] => 
    
                [isSerialized] => 
    
            )
    
    )
    
    


    이 결과에서, ReflectionClass::getInterfaces() 메서드는 MyInterface 인터페이스의 이름을 반환하는 것을 볼 수 있습니다.

    따라서, ReflectionClass::getInterfaces() 메서드는 인터페이스를 반환하는 것이 아니라, 인터페이스 이름을 반환하는 것입니다.

    2025-04-28 19:08

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

검색

게시물 검색