interface_exists()

interface_exists() — Checks if the interface has been defined.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.0.2, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

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

Parameters

ParameterTypeWhat it takes
$interfacestringThe interface name
$autoloadboolWhether to autoload if not already loaded.

Return value

Returns true if the interface given by interface has been defined, false otherwise.

Example

A runnable snippet:

// Check the interface exists before trying to use it if (interface_exists('MyInterface')) { class MyClass implements MyInterface { // Methods } }

See also

get_declared_interfaces(), class_implements(), class_exists(), enum_exists()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page interface_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.