<?php/** * In order to declare an interface, you need to use the keyword interface *interface iexampleinterface {} * Description (most developers choose to prefix with the capital letter I in front of the section name. In order to differentiate it from the class in the code and the generated document) * and to inherit the abstract class using the extends keyword, the implementation interface uses the Implements keyword. *class ExampleClass implements Iexampleinterface {} * mentioned earlier, the point that interfaces are better than abstract classes is that each class can use multiple interfaces. When you want to implement two or more than two interfaces in a class, we can separate them with commas. For example, if you have an object with an array style and want it to have both iteration and count capabilities, then we can define a class like this. *class Myarraylikeobject implements Iterator, countable {} * * * * interface Ispeedinfo {function Getmaximumspeed (); } class Car {Any base class method} class Fastcar extends Car implements Ispeedinfo {function Getmaximumspeed () {return 150;}} class Badcar extends fastcar{} $a = new Fastcar (); echo $a->getmaximumspeed ();echo ' <br/> '; Class Street extends Fastcar {protected $speedLimit;protected $cars;Public function __construct ($speedLimit = 200) {$this->cars = Array (); Initialize variables$this->speedlimit = $speedLimit;} function Isstreetlegal ($car) {if ($car instanceof Ispeedinfo) {if ($car->getmaximumspeed () < $this->speedlimit) {return true;} else {return false;}} else {Extension classes must implement Ispeedinfo to make street legalreturn false;}}Public Function Addcar ($car) {if ($this->isstreelegal ($car)) {Echo ' The Car was allowed on the road.$this->cars[] = $car;} else {Echo ' The Car is too fast and being not allowed on the road.}}}/* Class Street extends fastcar{} */$a = new Street (); echo $a->getmaximumspeed (); 150
interface--Interface class