
ReflectionMethod::isPublic 메서드는 메서드가 public 인지 확인하는 메서드입니다. 하지만, 이 메서드는 메서드가 public 인지 확인하는 것이 아니라, 메서드가 public accessibility를 가지는지 확인합니다.
PHP에서 public accessibility는 public, protected, private 메서드에 해당합니다. 따라서, protected 메서드는 public accessibility를 가집니다. 따라서, protected 메서드는 ReflectionMethod::isPublic 메서드에 의해 true로 반환됩니다.
private 메서드는 ReflectionMethod::isPublic 메서드에 의해 false로 반환됩니다. 하지만, ReflectionMethod::isPublic 메서드는 private 메서드를 확인할 수 없습니다. ReflectionMethod::isPrivate 메서드를 사용하여 private 메서드를 확인할 수 있습니다.
따라서, protected 메서드는 ReflectionMethod::isPublic 메서드에 의해 true로 반환되고, private 메서드는 ReflectionMethod::isPrivate 메서드를 사용하여 확인할 수 있습니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$reflectionMethod = new ReflectionMethod('MyClass', 'myMethod');
var_dump($reflectionMethod->isPublic()); // protected 메서드라 true로 반환됩니다.
var_dump($reflectionMethod->isPrivate()); // private 메서드라 true로 반환됩니다.
또한, ReflectionClass::isUserDefined 메서드를 사용하여 메서드가 사용자 정의 메서드인지 확인할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$reflectionMethod = $reflectionClass->getMethod('myMethod');
var_dump($reflectionMethod->isUserDefined()); // 사용자 정의 메서드라 true로 반환됩니다.
2025-07-25 07:50