Introduction to interface in php design mode
Like most abstract classes, interfaces also have abstract methods. no matter they cannot contain specific methods or variables in interfaces like abstract classes (as exceptions for abstraction)
Generally, the interface must start with the letter I or I.
All methods defined in the interface must be public, which is a feature of the interface.
When multiple interfaces are implemented, the methods in the interface cannot have duplicate names.
Interfaces can also be inherited by using the extends operator.
To implement the interface, you must use the method exactly the same as the method defined in the interface. Otherwise, a fatal error occurs.
Constants can also be defined in the interface. The use of interface constants and class constants is identical, but they cannot be overwritten by the quilt class or sub-interface.Understanding
The PHP interface class interface is the leader of a class and specifies the direction. the subclass must specify the method.
Simple code demonstration
/*** Interface ** is the same as most abstract classes, and interfaces also have abstract methods. no matter they cannot contain specific methods or variables in the interface like abstract classes (as an exception to abstraction) * It is generally agreed that the interface always starts with the letter I or I * All methods defined in the interface must be public, which is a feature of the interface * // defines an interface class, start with interface instead of classinterface ISMS {// you can define the constant const USERNAME = 'hhh '; // defines the method. the subclass must implement public function getInfo ($ info ); public function sendInfo ($ info);} // implements an interface using implements instead of extendsclass Register implements ISMS {// use an interface constant and use the scope resolution operator private $ username = ISMS:: USERNAME; public function getInfo ($ info) {return 'getinfo => '. $ info;} public function sendInfo ($ info) {return 'sendinfo => '. $ info;} public function getUserName () {return $ this-> username; }}$ test = new Register (); echo $ test-> getInfo ('enable '); // getInfo => Endaecho $ test-> sendInfo ('enabled'); // sendInfo => Endaecho $ test-> getUserName (); // hhh