We know that PHP5 or later allow OOP but not support multiple inheritance like C++ Does PHP7 supported Multiple Inheritance?
-
1No. It's not necessary in 99% of the situations people insist on using it for anyway. – tadman Aug 04 '17 at 07:12
-
2Java doesn't support multiple inheritance. – Ema.jar Aug 04 '17 at 07:26
2 Answers
I believe traits are a compromise to do things you'd usually do via multiple inheritance.
Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins.
http://php.net/manual/en/language.oop5.traits.php
Or in a less nicer way, one class can keep extending another class which implements what you want Class B extends A {}, Class C extends B {}, etc

- 3,214
- 2
- 32
- 39