An Interface allows the users to create programs, specifying the public methods that a class must implement, without involving the complexities and details of how the particular methods are implemented. It is generally referred to as the next level of abstraction. It resembles the abstract methods, resembling the abstract classes. An Interface is defined just like a class is defined but with the class keyword replaced by the interface keyword and just the function prototypes. The interface contains no data variables. The interface is helpful in a way that it ensures to maintain a sort of metadata for all the methods a programmer wishes to work on.
We can create only public functions inside interface.
More than one class inheritted by one class then we use interface
<?php // Interface definition interface Animal { public function makeSound(); } // Class definitions class Cat implements Animal { public function makeSound() { echo " Meow "; } } class Dog implements Animal { public function makeSound() { echo " Bark "; } } class Mouse implements Animal { public function makeSound() { echo " Squeak "; } } // Create a list of animals $cat = new Cat(); $dog = new Dog(); $mouse = new Mouse(); $animals = array($cat, $dog, $mouse); // Tell the animals to make a sound foreach($animals as $animal) { $animal->makeSound(); } ?>