
위의 코드를 실행하면 `$interfaces` 변수는 빈 배열이 됩니다.
이유는 `use Animal;` 문법은 Animal 클래스를 PetStore 클래스에 포함시켜주는 것이 아니라, Animal 클래스를 PetStore 클래스의 부모 클래스로 설정하는 것입니다.
따라서, PetStore 클래스는 Animal 클래스를 상속받는 것이고, Animal 클래스는 인터페이스이기 때문에 `$interfaces` 변수는 빈 배열이 됩니다.
만약, Animal 클래스가 인터페이스이면 `$interfaces` 변수는 ['Animal']이 됩니다.
예를 들어, Animal 클래스가 인터페이스인 경우:
#hostingforum.kr
php
interface Animal {}
class Dog implements Animal {}
class Cat implements Animal {}
class PetStore {
use Animal;
}
$reflection = new ReflectionClass('PetStore');
$interfaces = $reflection->getInterfaceNames();
print_r($interfaces); // ['Animal']
2025-06-01 18:20