The get_declared_interfaces Function
The get_declared_interfaces
function returns an array of names of all interfaces
that have been declared in the current script or loaded through autoloading.
The function does not accept any parameters.
Syntax
get_declared_interfaces();
Example
Get the list of all declared interfaces:
<?php
interface MyInterface1 {}
interface MyInterface2 {}
$res = get_declared_interfaces();
print_r($res);
?>
Code execution result:
[..., 'MyInterface1', 'MyInterface2']
Example
Check if the list contains a specific interface:
<?php
interface LoggerInterface {}
$interfaces = get_declared_interfaces();
$res = in_array('LoggerInterface', $interfaces);
var_dump($res);
?>
Code execution result:
true
Example
Compare the list of interfaces before and after declaring a new interface:
<?php
$before = get_declared_interfaces();
interface NewInterface {}
$after = get_declared_interfaces();
$res = array_diff($after, $before);
print_r($res);
?>
Code execution result:
['NewInterface']
See Also
-
the get_declared_classes function,
which returns classes -
the get_declared_traits function,
which returns traits -
the interface_exists function,
which checks an interface -
the class_implements function,
which returns class interfaces