
ReflectionClass::hasMethod 메소드는 클래스의 직접 정의된 메소드만 확인합니다. 상속받은 메소드는 포함되지 않습니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class ParentClass {
public function parentMethod() {}
}
class ChildClass extends ParentClass {
public function childMethod() {}
}
$reflection = new ReflectionClass('ChildClass');
echo $reflection->hasMethod('parentMethod') ? 'true' : 'false'; // false
echo $reflection->hasMethod('childMethod') ? 'true' : 'false'; // true
위 코드에서, ReflectionClass::hasMethod 메소드는 ChildClass의 직접 정의된 메소드인 childMethod를 확인하지만, 상속받은 메소드인 parentMethod는 확인하지 않습니다.
2025-03-25 13:59