The /*** interface defines the common behavior of different classes and then implements different functions within different classes. * Because the method implementation of the interface can be many, so the implementation of the method defined in the interface is various, this characteristic we call polymorphic * /Header"content-type:text/html; Charset=utf-8 ");//Remove Chinese garbled characters//interface keyword for defining interfaces interfaceicaneat{ Public functioneat($food);}The //implements keyword is used to indicate that a class implements an interface classHumanimplementsicaneat {//Implement an interface, you must provide a concrete implementation of the methods defined in the interface Public functioneat($food){Echo"Human::eat ()".$food."
"; } } classAnimalimplementsicaneat {//Implement an interface, you must provide a concrete implementation of the methods defined in the interface Public functioneat($food){Echo"Animal::eat ()".$food."
"; } }$pzy=NewHuman ();$pzy->eat ("Big Watermelon");$dog=NewAnimal ();$dog->eat ("big bones.");//instanceof is used to determine whether an object implements an interfaceVar_dump ($doginstanceofIcaneat); functioncheckeat($obj){if($objinstanceofIcaneat) {$obj->eat (' food '); }Else{Echo"The obj can ' t eat.
"; } }//The same line of code, for the implementation of the different interfaces of the object, the performance of different, called polymorphicCheckeat ($pzy); Checkeat ($dog);//Use extends to let interface inherit interface interfaceicanflyextendsicaneat{ Public functionfly();}//When a class implements a Subinterface, the method defined by the parent interface is also implemented in this class classHuman1implementsicanfly{ Public functionfly(){} Public functioneat($food){}}?>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the object-oriented PHP (iv), including aspects of the content, I hope that the PHP tutorial interested in a friend to help.