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

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

Example

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

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

Code execution result:

phptrue

Example

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

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

Code execution result:

phpfalse

Example

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

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

Code execution result:

phptrue

See Also