: This article mainly introduces object-oriented PHP (4). If you are interested in the PHP Tutorial, refer to it.
";}} ClassAnimalimplementsICanEat {// after an interface is implemented, you must provide the specific implementation of the methods defined in the interface publicfunctioneat ($ food) {echo" Animal: eat ()". $ food."
";}}$ Pzy = new Human (); $ pzy-> eat (" Big Watermelon "); $ dog = new Animal (); $ dog-> eat ("Big Bone"); // instanceof is used to determine whether an object has implemented an interface var_dump ($ doginstanceof ICanEat); functioncheckEat ($ obj) {if ($ objinstanceof ICanEat) {$ obj-> eat ('food');} else {echo "The obj can't eat.
";}}// The same line of code, for the implementation object passed in different interfaces, the performance is different, known as multi-state checkEat ($ pzy ); checkEat ($ dog); // use extends to let the interface inherit interface interfaceICanFlyextendsICanEat {publicfunctionfly ();} // when the class implements the sub-interface, the method defined by the parent interface must also implement classHuman1implementsICanFly {publicfunctionfly () {} publicfunctioneat ($ food) {}}?>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the object-oriented PHP (4), including the content, and hope to be helpful to friends who are interested in PHP tutorials.