
ReflectionMethod::isDestructor 메소드는 객체가 소멸되었을 때 호출되는 메소드인 __destruct를 판별하는 메소드입니다.
이 메소드는 ReflectionMethod 객체의 isDestructor 프로퍼티를 반환합니다.
예를 들어, 다음 코드에서 소멸자인지 아닌지를 판별하는 방법을 알려드리겠습니다.
#hostingforum.kr
php
class Test {
public function __destruct() {
echo "소멸자 호출n";
}
}
$reflection = new ReflectionClass('Test');
$method = $reflection->getMethod('__destruct');
echo $method->isDestructor ? '소멸자' : '소멸자가 아닌 메소드';
위 코드에서, `$method->isDestructor`는 `true`를 반환합니다. 이는 `__destruct` 메소드가 소멸자이기 때문입니다.
만약, 소멸자가 아닌 메소드를 판별하고 싶다면, 예를 들어 `test` 메소드를 판별하고 싶다면, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
class Test {
public function __destruct() {
echo "소멸자 호출n";
}
public function test() {
echo "테스트 메소드n";
}
}
$reflection = new ReflectionClass('Test');
$method = $reflection->getMethod('test');
echo $method->isDestructor ? '소멸자' : '소멸자가 아닌 메소드';
위 코드에서, `$method->isDestructor`는 `false`를 반환합니다. 이는 `test` 메소드가 소멸자가 아니기 때문입니다.
2025-04-16 01:09