
ReflectionMethod::getPrototype과 ReflectionClass::getPrototype의 차이점은 Prototype을 가져오는 대상이 다르기 때문입니다.
ReflectionMethod::getPrototype은 특정 메서드의 Prototype을 가져오기 때문에, 해당 메서드의 Prototype만 가져옵니다.
반면, ReflectionClass::getPrototype은 클래스의 Prototype을 가져오기 때문에, 클래스의 모든 메서드와 속성을 포함한 Prototype을 가져옵니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class A {
public function method1() {}
public function method2() {}
}
class B extends A {
public function method2() {}
}
$reflectionClass = new ReflectionClass('B');
$reflectionMethod = new ReflectionMethod('B', 'method2');
$prototype1 = $reflectionMethod->getPrototype();
$prototype2 = $reflectionClass->getPrototype();
print_r($prototype1);
print_r($prototype2);
이 코드를 실행하면, `$prototype1`에는 `B` 클래스의 `method2` 메서드만 포함된 Prototype이 포함되어 있습니다. 반면, `$prototype2`에는 `B` 클래스의 모든 메서드와 속성이 포함된 Prototype이 포함되어 있습니다.
2025-06-23 20:24