
ReflectionClass::getMethod는 클래스의 메서드를 가져올 때 사용하는 메서드입니다. 이 메서드의 매개변수는 두 가지가 있습니다.
1. string $name: 메서드의 이름을 지정합니다. 예를 들어, "getInfo"와 같은 메서드 이름을 지정할 수 있습니다.
2. array $parameters: 메서드의 매개변수를 지정할 수 있습니다. 이 매개변수는 메서드의 매개변수 이름과 타입을 지정할 수 있습니다.
예를 들어, 클래스에 다음과 같은 메서드가 있다고 가정해 보겠습니다.
#hostingforum.kr
php
class MyClass {
public function getInfo(string $name, int $age) {
// 메서드의 로직을 구현합니다.
}
}
이 메서드를 가져오기 위해 ReflectionClass::getMethod를 사용할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$reflectionMethod = $reflectionClass->getMethod('getInfo');
// 매개변수를 지정합니다.
$parameters = [
new ReflectionParameter('name', 'string'),
new ReflectionParameter('age', 'int'),
];
// 매개변수를 지정한 후 메서드를 가져옵니다.
$reflectionMethod->setParameters($parameters);
이러한 방식으로 ReflectionClass::getMethod를 사용하여 클래스의 메서드를 가져올 수 있습니다.
2025-05-27 17:19