interface_exists
Description
The interface_exists of Class / Object for PHP checks if the interface has been defined.
Syntax
interface_exists ( string $interface_name [, bool $autoload = TRUE ] ) : bool
Parameters
interface_name
The interface name
autoload
Whether to call __autoload or not by default.
Return
Returns TRUE if the interface given by interface_name has been defined, FALSE otherwise.
Examples
1 · interface_name
<? interface myinterface { } $interface_name = "myinterface"; $return = interface_exists($interface_name); var_export($return);
true
2 · autoload
<? interface myinterface { } $interface_name = "myinterface"; $autoload = false; $return = interface_exists($interface_name, $autoload); var_export($return);
true
3 · 1
<? interface myinterface { } $interface_name = "myinterface"; $return = interface_exists($interface_name); if ($return) { class myclass implements myinterface { function __construct() { echo __METHOD__; } } new myclass(); }
myclass::__construct