Before introducing the interface, we need to know why we should use the interface. here we will introduce it to you. Why should I use interfaces? In computer languages, only a few object-oriented languages support multi-inheritance. the PHP language we learn is the same as most languages and does not support multi-inheritance. To put it bluntly, a parent class can have multiple child classes, but only one child class can have one child class. What is multi-inheritance? Multi-inheritance is a subclass that inherits two or more parent classes, that is, multi-inheritance, which is not allowed in PHP. If you want to implement multiple inheritance functions in PHP, you need to know why to use the interfaces before using the interfaces. Why should I use interfaces? In computer languages, only a few object-oriented languages support multi-inheritance. the PHP language we learn is the same as most languages and does not support multi-inheritance. To put it bluntly, a parent class can have multiple child classes, but only one child class can have one child class. What is multi-inheritance? Multi-inheritance is a subclass that inherits two or more parent classes, that is, multi-inheritance, which is not allowed in PHP. If you want to implement multiple inheritance functions in PHP, you need to use interfaces. The interface can be seen as a solution to multi-inheritance. The PHP object-oriented interface is similar to other object-oriented language interfaces. Interface class syntax Introduction: The interface class is declared by the interface keyword, and the class can only contain unimplemented methods and some member variables. the format is as follows: interface InterfaceName {function interfaceName1 () {} function interfaceName2 (
1. PHP object-oriented multi-inheritance and interface usage
Introduction: an interface contains a set of functions that can be implemented by a class or structure. for example, an interface can include behaviors from multiple sources in the class. Because the C # language does not support multi-inheritance, multiple inheritance can be implemented through interfaces. In short, an interface only contains the declaration of members (attributes, events, and indexers. The specific implementation of a member's definition is determined by its derived class.
5. programmers share their learning experience on PHP interfaces _ PHP Tutorial
Introduction: programmers share their learning experience on PHP interfaces. LieHuo. Net (LieHuo. Net) network programming recently encountered difficulties in learning the PHP5 interface. The book says it is a way to implement multiple inheritance, but I still don't know how to implement it.
6. PHP interface learning _ PHP Tutorial
Introduction: PHP interface learning. I recently encountered difficulties in learning the php (as a mainstream development language) 5 interface. The book says it is a way to implement multi-inheritance, but I still don't know how to implement it.
7. php implements multiple inheritance instances
Introduction: A friend who recently developed php asked a question about the multi-inheritance of php. after talking for a long time, the two people did not actually understand what multi-inheritance is. today, I am free, the concept of multi-inheritance is explained in detail, and some opinions on implementing multi-inheritance in php are also discussed.
8. java software engineer learning php-14. object-oriented
Introduction: java programmers learn php-14. object-oriented similarities: 1. also class + Method 2. multi-inheritance is not allowed. you can also use interfaces to implement multi-inheritance. there are also abstract classes 5. there are also static methods 6. you can also disable extension by using the final keyword: 1. the class itself does not have access modifier2. the default access modifier attribute and method is public.
9. [transfer] PHP implements multiple inheritance through interfaces
Introduction: [transfer] PHP implements multi-inheritance through interfaces. Although PHP classes are single-inherited, multiple inheritance can be implemented through other special methods, such as using interfaces, you only need to abstract the features of a class as an interface and implement the interface to make the object have multiple parts. in this way, you can simulate multiple inheritance. The following is an example of simulating multiple inheritance using interfaces. the source code is as follows:
10. programmers share their learning experience on PHP interfaces
Introduction: programmers share their learning experience on PHP interfaces. LieHuo. Net (LieHuo. Net) network programming recently encountered difficulties in learning the PHP5 interface. The book says it is a way to implement multiple inheritance, but I still don't know how to implement it.
[Related Q & A recommendations ]:
Does the use of trait + interface in PHP work together perfectly implement multiple inheritance?
The above is a detailed recommendation for 10 articles that implement multi-inheritance. For more information, see other related articles in the first PHP community!