Computer >> Computer tutorials >  >> Programming >> PHP

interface_exists() function in PHP


The interface_exists() function checks if the interface has been defined. It returns TRUE if the interface given by name_of_interface has been defined, else FALSE is returned.

Syntax

interface_exists(name_of_interface, autoload)

Parameters

  • name_of_interface − The interface name.

  • autoload − To call __autoload or not by default

Return

The interface_exists() function returns TRUE if the interface given by name_of_interface has been defined. It returns FALSE otherwise.

Example

The following is an example −

<?php
   if (interface_exists('DemoInterface')) {
      class MyClass implements DemoInterface {
         // Methods
      }
   }
?>