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 −

 Live Demo

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

212 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements