
ReflectionMethod::__toString 메서드는 ReflectionMethod 객체를 문자열로 변환하는 메서드입니다. 하지만 이 메서드는 사용할 수 없습니다. 대신에, ReflectionMethod::getName() 메서드를 사용하여 클래스의 메서드 이름을 가져올 수 있습니다.
#hostingforum.kr
php
$reflectionMethod = new ReflectionMethod('MyClass', 'myMethod');
echo $reflectionMethod->getName(); // myMethod를 출력합니다.
또한, ReflectionMethod::__toString 메서드는 private 메서드나 protected 메서드의 이름을 가져올 수 없습니다. 이 경우, ReflectionClass::getMethods() 메서드를 사용하여 클래스의 모든 메서드를 가져오고, foreach 루프를 사용하여 메서드 이름을 가져올 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
foreach ($reflectionClass->getMethods() as $method) {
echo $method->getName() . "n";
}
2025-03-30 01:24