Implementation of the interface
The <?php//interface keyword is used to define an interface interface icaneat{ //interface inside the method does not need to implement public function eat ($food);} The Implements keyword is used when a class implements an interface class Human implements icaneat{ //Implements an interface and must provide a concrete implementation of the method in the interface public function eat ($food) { echo "Human eating". $food; }? >
So, after the definition of this pass,
By instantiating an object
$peroson 1=new Human ();
$person 1->eat (' Apple ');
The result of the output is
Human eating apple
The <?php//interface keyword is used to define an interface interface icaneat{ //interface inside the method does not need to implement public function eat ($food);} The Implements keyword is used when a class implements an interface class Human implements icaneat{ //Implements an interface and must provide a concrete implementation of the method in the interface public function eat ($food) { echo "Human eating". $food. " \ n "; }} $person 1 = new Human (), $person 1->eat (' Apple ');//We can determine whether an object implements an interface Var_dump ($person 1 instanceof by instanceof keyword) Icaneat);//In the example above we can use this keyword to determine whether the Icaneat interface is implemented?>
Then the output should be
Human eating apple
Bool (True)
The <?php//interface keyword is used to define an interface interface icaneat{//interface methods do not need to implement public function eat ($food);} The Implements keyword is used for classes that implement an interface class Human implements icaneat{//implement an interface, you must provide a concrete implementation of the method in the interface public function eat ($food) {echo "Human Eating ". $food." \ n ";}} $person 1 = new Human (), $person 1->eat (' Apple ');//We can determine whether an object implements an interface Var_dump ($person 1 instanceof by instanceof keyword) Icaneat);//In the above example, we can use this keyword to determine whether the implementation of Icaneat this interface//class can inherit, then the interface can also be inherited interface Icansleep extends icaneat{public function sleep ();} When a class implements a Subinterface, the method defined by the parent interface also needs to be implemented in the class to specifically implement class Human1 implements icansleep{public function eat ($food) {} Public Function sleep () { }}?>