함수 interface_exists

함수 interface_exists는 지정된 인터페이스가 현재 스코프에 존재하는지 확인합니다. 첫 번째 매개변수로 문자열 형태의 인터페이스 이름을, 두 번째 선택적 매개변수로 클래스 자동 로딩을 사용할지 여부를 나타내는 플래그를 받습니다.

구문

phpinterface_exists(string $interface, bool $autoload = true): bool

예제

'Countable' 인터페이스의 존재를 확인해 보겠습니다:

php<?php
  $res = interface_exists('Countable');
  var_dump($res);
?>

코드 실행 결과:

phptrue

예제

존재하지 않는 인터페이스의 존재를 확인해 보겠습니다:

php<?php
  $res = interface_exists('NonExistingInterface');
  var_dump($res);
?>

코드 실행 결과:

phpfalse

예제

자동 로딩이 비활성화된 상태에서 인터페이스 존재를 확인해 보겠습니다:

php<?php
  $res = interface_exists('Iterator', false);
  var_dump($res);
?>

코드 실행 결과:

phptrue

함께 보기