Is Multiple Inheritance allowed at class level in PHP?
Multiple inheritance suffers from the Diamond Problem, which has not been (agreed upon how to be) solved in PHP yet. Thus, there is no multiple inheritance in PHP.
BaseClass
/\
/ \
ClassA ClassB
\ /
\/
ClassC
If both ClassA
and ClassB
defined their own method foo()
, which one would you call in ClassC
?
You are encouraged to either use object composition or interfaces (which do allow multiple inheritance) or - if you are after horizontal reuse - look into the Decorator or Strategy pattern until we have Traits (or Grafts or whatever they will be called then).
Some Reference: