php can implement multiple interfaces. PHP can use the "implements" keyword to bind a class to one or more interfaces, and let the class implement all the methods defined in the bound interface.
Operating system for this tutorial: Windows 10 system, php8.1.3 version, Dell G3 computer.
PHP can implement multiple interfaces.
In PHP, use the "implements" keyword to bind a class to one or more interfaces, allowing the class to implement all methods defined in the bound interface.
The following is a sample code:
interface Car { public function setModel($name); public function getModel(); } interface Vehicle { public function setColor($rgb); public function getColor(); } class MiniCar implements Car, Vehicle { private $model; private $color; public function setModel($name) { $this -> model = $name; } public function getModel() { return $this -> model; } public function setColor($rgb) { $this -> color = $rgb; } public function getColor() { return $this -> color; } }
In the above code, two interfaces "Car" and "Vehicle" are defined, each interface has abstract methods. Next, a class named "MiniCar" is defined, which implements both interfaces, so MiniCar implements all methods of these two interfaces.
The above is the detailed content of Can php implement multiple interfaces?. For more information, please follow other related articles on the PHP Chinese website!