317 of 410 menu

The interface_exists Function

The interface_exists function checks if the specified interface exists in the current scope. Its first parameter is the interface name as a string, the second optional parameter is a flag indicating whether to use autoloading.

Syntax

interface_exists(string $interface, bool $autoload = true): bool

Example

Let's check the existence of the 'Countable' interface:

<?php $res = interface_exists('Countable'); var_dump($res); ?>

Code execution result:

true

Example

Let's check the existence of a non-existing interface:

<?php $res = interface_exists('NonExistingInterface'); var_dump($res); ?>

Code execution result:

false

Example

Let's check the existence of an interface with autoloading disabled:

<?php $res = interface_exists('Iterator', false); var_dump($res); ?>

Code execution result:

true

See Also

byenru