Reflection ReflectionClass::getMethods
(PHP 5, PHP 7, PHP 8)
ReflectionClass::getMethods — 메서드 배열을 가져옵니다.
설명
public ReflectionClass::getMethods(?int $filter
= null
): array
클래스의 메서드 배열을 가져옵니다.
매개변수
filter
- 특정 속성이 있는 메서드만 포함하도록 결과를 필터링합니다. 기본값은 필터링 없음입니다.
ReflectionMethod::IS_STATIC
,ReflectionMethod::IS_PUBLIC
,ReflectionMethod::IS_PROTECTED
,ReflectionMethod::IS_PRIVATE
,ReflectionMethod::IS_ABSTRACT
,ReflectionMethod::IS_FINAL
의 모든 비트 분리를 통해 지정된 속성을 가진 모든 메서드가 반환됩니다.참고: 다른 비트 연산(예: ~)은 예상대로 작동하지 않습니다. 즉, 예를 들어 모든 비정적 메서드를 검색하는 것은 불가능합니다.
반환 값
각 메서드를 반영하는 ReflectionMethod 개체의 배열입니다.
변경 로그
버전 | 설명 |
---|---|
7.2.0 | filter 는 이제 nullable입니다. |
Examples
예제 #1 ReflectionClass::getMethods()의 기본 사용법
<?php
class Apple {
public function firstMethod() { }
final protected function secondMethod() { }
private static function thirdMethod() { }
}
$class = new ReflectionClass('Apple');
$methods = $class->getMethods();
var_dump($methods);
?>
위의 예는 다음을 출력합니다.
array(3) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(11) "firstMethod" ["class"]=> string(5) "Apple" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(12) "secondMethod" ["class"]=> string(5) "Apple" } [2]=> object(ReflectionMethod)#4 (2) { ["name"]=> string(11) "thirdMethod" ["class"]=> string(5) "Apple" } }
예제 #2 ReflectionClass::getMethods()의 결과 필터링
<?php
class Apple {
public function firstMethod() { }
final protected function secondMethod() { }
private static function thirdMethod() { }
}
$class = new ReflectionClass('Apple');
$methods = $class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_FINAL);
var_dump($methods);
?>
위의 예는 다음을 출력합니다.
array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(12) "secondMethod" ["class"]=> string(5) "Apple" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(11) "thirdMethod" ["class"]=> string(5) "Apple" } }
기타
- ReflectionClass::getMethod() - 클래스 메서드에 대한 ReflectionMethod를 가져옵니다.
- get_class_methods() - 클래스 메서드의 이름을 가져옵니다.