
method_exists 함수는 클래스의 인스턴스 변수에 메소드가 정의되어 있지 않은 경우 에러가 발생할 수 있습니다. 이 경우를 피하기 위해, 클래스 이름을 사용하여 method_exists 함수를 호출하는 것이 좋습니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
class MyClass {
public function myMethod() {}
}
if (method_exists('MyClass', 'myMethod')) {
echo 'myMethod 메소드가 존재합니다.';
} else {
echo 'myMethod 메소드가 존재하지 않습니다.';
}
또는, 클래스의 인스턴스를 만들지 않고 method_exists 함수를 호출할 수도 있습니다.
#hostingforum.kr
php
class MyClass {
public function myMethod() {}
}
$obj = new MyClass();
if (method_exists($obj, 'myMethod')) {
echo 'myMethod 메소드가 존재합니다.';
} else {
echo 'myMethod 메소드가 존재하지 않습니다.';
}
이러한 방법을 사용하면, method_exists 함수를 사용하여 클래스의 메소드가 존재하는지 확인할 수 있습니다.
2025-07-20 06:08