InThe code for the multiple inheritance of PHP5 is as follows:
- <?
- // PHP5 interface --- similar to JAVA ~ Dizzy
- Interface IFOne {
- Function getName ();
- }
- Interface IFTwo {
- Function getID ();
- }
- // PHP abstract class
- Abstract class AbsClsOne {
- Var $ name;
- Function setName ($ name ){
- $ This->Name= $ Name;
- }
- }
- Abstract class AbsClsTwo {
- Var $ id;
- Function setID ($ id ){
- $ This->Id= $ Id;
- }
- }
- // Multiple implementations of single inheritance
- Class ExtendsMoreCls extends AbsClsOne implements IFOne, IFTwo {
- Var $ id;
- Private static $PriVar="Private";
- Function _ construct () {// PHP5 Constructor
- Self: $PriVar="Set private";
- $ This->Id=0;
- }
- Function _ destruct () {// destructor
- Echo "ExtendsMoreCls destruct ";
- }
- Function getName (){
- Return $ this->Name;
- }
- Function getID (){
- Return $ this->Id;
- }
- Public static function clsStaticFunc (){
- Echo "static function ";
- }
- }
-
- $Emc=NewExtendsMoreCls ();
- $ Emc->SetName ("kj021320 ");
- Echo $ emc->GetName ();
- Echo"<Br>";
- Echo $ emc->GetID ();
- Echo"<Br>";
- ExtendsMoreCls: clsStaticFunc (); // call the static method
- Echo"<Br>";
- ?>
The output structure is
Kj021320
0
Static function
ExtendsMoreCls destruct
It is hoped that the implementation code of PHP5 multi-inheritance can be helpful to friends in need.