Funkcija get_declared_interfaces

Funkcija get_declared_interfaces atgriež visu interfešu nosaukumu masīvu, kuri ir deklarēti pašreizējā skriptā vai ielādēti caur automātisko ielādi. Funkcija nepieņem parametrus.

Sintakse

phpget_declared_interfaces();

Piemērs

Iegūsim visu deklarēto interfešu sarakstu:

php<?php
  interface MyInterface1 {}
  interface MyInterface2 {}
  
  $res = get_declared_interfaces();
  print_r($res);
?>

Koda izpildes rezultāts:

php[..., 'MyInterface1', 'MyInterface2']

Piemērs

Pārbaudīsim, vai sarakstā ir iekļauts noteikts interfeiss:

php<?php
  interface LoggerInterface {}
  
  $interfaces = get_declared_interfaces();
  $res = in_array('LoggerInterface', $interfaces);
  var_dump($res);
?>

Koda izpildes rezultāts:

phptrue

Piemērs

Salīdzināsim interfešu sarakstu pirms un pēc jauna interfeisa deklarēšanas:

php<?php
  $before = get_declared_interfaces();
  interface NewInterface {}
  $after = get_declared_interfaces();
  
  $res = array_diff($after, $before);
  print_r($res);
?>

Koda izpildes rezultāts:

php['NewInterface']

Skatiet arī