Notice
Like most abstract classes, interface has an abstract approach, whether it can include specific methods or variables (as an exception to abstractions) in an interface, as in an abstract class.
General conventions interfaces always start with the letter I or I
All methods defined in the interface must be public, which is the attribute of the interface
When implementing multiple interfaces, the methods in the interface cannot have duplicate names.
Interfaces can also be inherited by using the extends operator.
Class to implement an interface, it must be in a way that is exactly the same as the method defined in the interface. Failure to do so can result in fatal errors.
Constants can also be defined in an interface. Interface constants and class constants are used exactly the same, but cannot be overridden by subclasses or sub-interfaces.Understand
PHP Interface Class interface is the leader of a class, indicating the direction, the subclass must complete its specified method
Simple Code Demonstration
/** * Interface interface * Like most abstract classes, interface also has an abstract method, whether or not it can contain specific methods or variables (as abstract exceptions) in the interface, as in the case of abstract classes. All methods defined in the interface that always begin with the letter I or I * must be Public, which is the interface's attribute *///defines an interface class that begins with interface instead of ClassInterface isms{ //can define constants Const USERNAME = ' HHH '; Defined methods, subclasses must implement public function GetInfo ($info); Public Function Sendinfo ($info);} Implement an interface that uses implements instead of Extendsclass Register implements isms{ //using interface constants, requiring 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 (' Enda '); Getinfo=>endaecho $test->sendinfo (' Enda '); Sendinfo=>endaecho $test->getusername (); Hhh