클래스/객체 method_exists

(PHP 4, PHP 5, PHP 7, PHP 8)

method_exists — 클래스 메소드가 존재하는지 확인


설명

method_exists(object|string $object_or_class, string $method): bool

지정된 object_or_class에 클래스 메서드가 있는지 확인합니다.


매개변수

object_or_class
개체 인스턴스 또는 클래스 이름
method
메서드 이름

반환 값

method에 의해 주어진 메서드가 주어진 object_or_class에 대해 정의되어 있으면 true를 반환하고, 그렇지 않으면 false를 반환합니다.


Examples

예제 #1 method_exists() 예제

                  
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
                  
                

위의 예는 다음을 출력합니다.

bool(true)
                

예제 #2 정적 method_exists() 예제

                  
<?php
var_dump(method_exists('Directory','read'));
?>
                  
                

위의 예는 다음을 출력합니다.

bool(true)
                

메모

메모: 클래스가 아직 알려지지 않은 경우 이 함수를 사용하면 등록된 autoloaders가 사용됩니다.


기타

  • function_exists() - 주어진 함수가 정의되면 true를 반환합니다.
  • is_callable() - 현재 범위에서 값을 함수로 호출할 수 있는지 확인합니다.
  • class_exists() - 클래스가 정의되었는지 확인