함수 interface_exists
함수 interface_exists는 지정된 인터페이스가 현재 스코프에 존재하는지 확인합니다. 첫 번째 매개변수로 문자열 형태의 인터페이스 이름을, 두 번째 선택적 매개변수로 클래스 자동 로딩을 사용할지 여부를 나타내는 플래그를 받습니다.
구문
interface_exists(string $interface, bool $autoload = true): bool
예제
'Countable' 인터페이스의 존재를 확인해 보겠습니다:
<?php
$res = interface_exists('Countable');
var_dump($res);
?>
코드 실행 결과:
true
예제
존재하지 않는 인터페이스의 존재를 확인해 보겠습니다:
<?php
$res = interface_exists('NonExistingInterface');
var_dump($res);
?>
코드 실행 결과:
false
예제
자동 로딩이 비활성화된 상태에서 인터페이스 존재를 확인해 보겠습니다:
<?php
$res = interface_exists('Iterator', false);
var_dump($res);
?>
코드 실행 결과:
true
함께 보기
-
class_exists 함수,
클래스를 확인합니다 -
trait_exists 함수,
트레이트를 확인합니다 -
get_declared_interfaces 함수,
인터페이스들을 반환합니다 -
class_implements 함수,
클래스의 인터페이스들을 반환합니다