interface_exists

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

interface_name

<?

interface myinterface
{
}

$interface_name = "myinterface";

$return = interface_exists($interface_name);

var_export($return);

?>
true

autoload

<?

interface myinterface
{
}

$interface_name = "myinterface";
$autoload = false;

$return = interface_exists($interface_name, $autoload);

var_export($return);

?>
true

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

PHP

Home Menu