라이브러리
[PHP] get_class_methods - 클래스 메서드 이름을 가져옵니다.
PHP의 get_class_methods() 함수
PHP의 `get_class_methods()` 함수는 특정 클래스의 메서드 목록을 반환하는 함수입니다. 이 함수는 클래스의 모든 메서드 이름을 배열로 반환합니다.
# 함수의 사용법
`get_class_methods()` 함수는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
get_class_methods(string $class_name)
* `$class_name`: 반환할 클래스 이름을 지정합니다.
# 예제
다음 예제에서는 `get_class_methods()` 함수를 사용하여 `stdClass` 클래스의 메서드 목록을 반환합니다.
#hostingforum.kr
php
// stdClass 클래스의 메서드 목록을 반환합니다.
$methods = get_class_methods('stdClass');
print_r($methods);
출력:
#hostingforum.kr
php
Array
(
[0] => __construct
[1] => __destruct
[2] => __clone
[3] => __wakeup
[4] => __sleep
[5] => __set
[6] => __get
[7] => __isset
[8] => __unset
[9] => __call
[10] => __callStatic
[11] => __toString
)
# 사용 예시
다음 예제에서는 `get_class_methods()` 함수를 사용하여 사용자 정의 클래스의 메서드 목록을 반환합니다.
#hostingforum.kr
php
// 사용자 정의 클래스
class User {
public function __construct($name) {
$this->name = $name;
}
public function sayHello() {
echo "Hello, {$this->name}!";
}
public function sayGoodbye() {
echo "Goodbye, {$this->name}!";
}
}
// User 클래스의 메서드 목록을 반환합니다.
$methods = get_class_methods('User');
print_r($methods);
출력:
#hostingforum.kr
php
Array
(
[0] => __construct
[1] => sayHello
[2] => sayGoodbye
)
# 참고
* `get_class_methods()` 함수는 클래스의 모든 메서드 이름을 반환합니다. 이 함수는 상속된 메서드도 포함합니다.
* `get_class_methods()` 함수는 클래스 이름을 지정할 때, 클래스 이름을 문자열로 지정해야 합니다. 예를 들어, `get_class_methods(User)` 대신 `get_class_methods('User')`를 사용해야 합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.