Reflection ReflectionClass::isInstance
(PHP 5, PHP 7, PHP 8)
ReflectionClass::isInstance — 예를 들어 클래스를 확인합니다.
설명
public ReflectionClass::isInstance(object $object
): bool
개체가 클래스의 인스턴스인지 확인합니다.
매개변수
object
- 비교할 대상입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 ReflectionClass::isInstance() 관련 예제
<?php
// Example usage
$class = new ReflectionClass('Foo');
if ($class->isInstance($arg)) {
echo "Yes";
}
// Equivalent to
if ($arg instanceof Foo) {
echo "Yes";
}
// Equivalent to
if (is_a($arg, 'Foo')) {
echo "Yes";
}
?>
위의 예는 다음과 유사한 결과를 출력합니다.
Yes Yes Yes
기타
- ReflectionClass::isInterface() - 클래스가 인터페이스인지 확인
- Type operators (instanceof)
- Object Interfaces
- is_a() - 개체가 이 개체 유형인지 또는 이 개체 유형이 부모 중 하나인지 확인합니다.