For those who learn PHP language, for the PHP interface class may not understand very deep, then we will be specific to the PHP interface class interface use.
How to use PHP XmlReader to parse XML document correctly
In-depth interpretation of PHP Domxpath in XML file parsing
Featured several powerful PHP template engines
Key points of PHP usage tips
How to create an XML file correctly using PHP dom-xml
In fact, their role is very simple, when a lot of people to develop a project, may go to call someone else to write some of the classes, then you will ask, how do I know how his implementation of a function is named, this time the PHP interface class interface play a role, when we define an interface class, The way inside it is that the following subclass must be implemented, such as:
Interface Shop {public function buy ($gid); Public function sell ($gid); Public Function view ($gid); }
Declares a shop interface class, defines three methods: Buy, Sell (Sell), see (view), then inherit all subclasses of this class must implement these 3 methods less one, if the subclass does not implement these words, it will not run. In fact, the interface class is plainly, is a class template, a class of provisions, if you belong to this category, you have to follow my rules, less one can not, but specific how you do, I don't care, it is your business, such as:
Class Baseshop implements shop {public function buy ($gid) { echo (' You have purchased the ID: '. $gid. '); } Public function Sell ($gid) { echo (' You sold the ID: '. $gid. '); } Public Function View ($gid) { echo (' You have viewed the item ID: '. $gid. ');} }
You think, in a multi-person cooperation of large projects, with the interface class is how convenient, so you do not have to ask others, your method name of the function is what, of course, if you like this I have no way.
Conclusion: PHP Interface class interface is the leader of a class, indicating the direction, the subclass must complete its specified method.
<?phpinterface Shop {public function buy ($gid); Public function sell ($gid); Public Function view ($gid); } Class Baseshop implements shop {public function buy ($gid) { echo (' You have purchased the ID: '. $gid. '); } Public function Sell ($gid) { echo (' You sold the ID: '. $gid. '); } Public Function View ($gid) { echo (' You have viewed the item ID: '. $gid. ');} } $haha = new Baseshop (); $haha->buy (' 123 ');