Inheritance simplifies the creation of objects, classes, and increases the weight of the code, but PHP only supports single inheritance, and if multiple inheritance is to be implemented, multiple interfaces will be used.
The interface is declared by the interface keyword, and the class can contain only the methods and some member variables that are not implemented, in the following format:
Interface interfacename{
function interfaceName1 ();
function interfaceName2 ();
...
}
Subclasses are implemented via the Implements keyword, and if multiple interfaces are to be implemented, a comma "," connection should be used between each interface. And all the methods that are not implemented are implemented in subclasses, otherwise PHP will go wrong. The format is as follows:
Class Subclass Implments interfacename1,interfacename2{
function interfaceName1 () {
function implementation
}
function InterfaceName2 () {
function implementation
}
}
The sample code is as follows:
<?php //Declaration interface a interface A{ function Aa();}//Declaration Interface B interface B{ function Bb();} class Am implements A{ function Aa(){ Echo "Aa is a php coder"; } } class Bm implements A,B{ function Aa(){ Echo "Mike is a php coder<br>";Echo "Mike is an iOS coder<br>"; } function Bb(){ Echo "Jack is a Java coder"; } }$jack=NewAm ();$bluce=NewBm ();$jack->aa ();Echo"<br>";$bluce->aa ();$bluce->BB ();?>
The results of the operation are as follows:
The use of interfaces for PHP development