Interface allows us to implement multiple classes in a single class, and multiple inheritances can be implemented using the interface.
PHP interface some properties
- Interface not inherited alway implemented
- Interface can not contain properties
- Interface have abstract methods, need to implemented in derived class
Example
interface Animal{
public function animal_sound();
}
interface AnimalCanEat{
public function animal_can_eat();
}
class Dog implements Animal, AnimalCanEat{
public function animal_sound(){
echo "Dog can bark <br>";
}
public function animal_can_eat(){
echo "Dog can eat <br>";
}
}
$dog= new Dog();
$dog->animal_sound();
$dog->animal_can_eat();