PHP interface_exists() Function
The PHP interface_exists() function is used to check whether or not the given interface has been defined. It returns true if the given interface is defined, else returns false.
Syntax
interface_exists(interface, autoload)
Parameters
interface |
Required. Specify the interface name to check. The name is matched in a case-insensitive manner. |
autoload |
Optional. Specify whether to call __autoload or not by default. |
Return Value
Returns true if interface is a defined interface, false otherwise.
Example: interface_exists() example
The example below shows the usage of interface_exists() function.
<?php //checking that the interface exists //before trying to use it if (interface_exists('MyInterface')) { class MyClass implements MyInterface { // Methods } echo "A class using 'MyInterface' is created."; } else { echo "'MyInterface' do not exist!."; } ?>
The output of the above code will be:
'MyInterface' do not exist!.
❮ PHP Classes/Objects Reference