함수 get_declared_interfaces
함수 get_declared_interfaces는 현재 스크립트에서 선언되었거나 자동 로드를 통해 로드된 모든 인터페이스의 이름 배열을 반환합니다.
이 함수는 매개변수를 받지 않습니다.
문법
get_declared_interfaces();
예제
선언된 모든 인터페이스 목록 가져오기:
<?php
interface MyInterface1 {}
interface MyInterface2 {}
$res = get_declared_interfaces();
print_r($res);
?>
코드 실행 결과:
[..., 'MyInterface1', 'MyInterface2']
예제
목록에 특정 인터페이스가 포함되어 있는지 확인하기:
<?php
interface LoggerInterface {}
$interfaces = get_declared_interfaces();
$res = in_array('LoggerInterface', $interfaces);
var_dump($res);
?>
코드 실행 결과:
true
예제
새 인터페이스 선언 전후의 목록 비교하기:
<?php
$before = get_declared_interfaces();
interface NewInterface {}
$after = get_declared_interfaces();
$res = array_diff($after, $before);
print_r($res);
?>
코드 실행 결과:
['NewInterface']
함께 보기
-
get_declared_classes 함수,
클래스를 반환합니다. -
get_declared_traits 함수,
트레이트를 반환합니다. -
interface_exists 함수,
인터페이스 존재를 확인합니다. -
class_implements 함수,
클래스가 구현한 인터페이스를 반환합니다.