⊗ppOpIfIFI 71 of 107 menu

Inheritance of Interfaces From Each Other in OOP in PHP

Interfaces, just like classes, can inherit from each other using the operator extends. Let's look at an example. Suppose we have such an interface from the previous lesson:

<?php interface iRectangle { public function __construct($a, $b); public function getSquare(); public function getPerimeter(); } ?>

However, we already have an interface iFigure, which describes some of the methods of our interface:

<?php interface iFigure { public function getSquare(); public function getPerimeter(); } ?>

Let's make the interface iRectangle inherit the methods of the interface iFigure:

<?php interface iRectangle extends iFigure { public function __construct($a, $b); } ?>

Make an interface iUser with methods getName, setName, getAge, setAge.

Make an interface iEmployee, inheriting from the interface iUser and adding methods getSalary and setSalary to it.

Make a class Employee, implementing the interface iEmployee.

byenru