함수 class_implements

함수 class_implements는 지정된 클래스나 인터페이스가 구현하는 인터페이스 이름들의 배열을 반환합니다. 첫 번째 매개변수로 객체나 문자열 형태의 클래스 이름이 전달되며, 두 번째 선택적 매개변수는 자동 로딩을 사용할지 여부를 결정합니다.

구문

phpclass_implements(
  object|string $class,
  [bool $autoload = true]
): array|false

예제

내장 클래스 Exception의 인터페이스를 가져옵니다:

php<?php
  $res = class_implements('Exception');
  print_r($res);
?>

코드 실행 결과:

php['Throwable']

예제

사용자 정의 인터페이스와 클래스를 만든 후, 구현된 인터페이스를 확인해 봅시다:

php<?php
  interface MyInterface {}
  class MyClass implements MyInterface {}
  
  $res = class_implements('MyClass');
  print_r($res);
?>

코드 실행 결과:

php['MyInterface']

예제

인터페이스 자체의 인터페이스를 확인해 봅시다:

php<?php
  interface ParentInterface {}
  interface ChildInterface extends ParentInterface {}
  
  $res = class_implements('ChildInterface');
  print_r($res);
?>

코드 실행 결과:

php['ParentInterface']

함께 보기

  • 부모 클래스를 반환하는 함수 class_parents
  • 클래스가 사용하는 트레이트를 반환하는 함수 class_uses