Funkcija class_implements

Funkcija class_implements vraća niz imena interfejsa koje implementira navedena klasa ili interfejs. U prvi parametar se prosleđuje objekat ili ime klase u vidu stringa, a drugi opcioni parametar određuje da li treba koristiti automatsko učitavanje.

Sintaksa

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

Primer

Dobijmo interfejse za ugrađenu klasu Exception:

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

Rezultat izvršavanja koda:

php['Throwable']

Primer

Napravimo sopstveni interfejs i klasu, pa proverimo implementirane interfejse:

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

Rezultat izvršavanja koda:

php['MyInterface']

Primer

Proverimo interfejse za sam interfejs:

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

Rezultat izvršavanja koda:

php['ParentInterface']

Pogledajte takođe

  • funkciju class_parents,
    koja vraća roditeljske klase
  • funkciju class_uses,
    koja vraća trejtove koje klasa koristi