Is Multiple Inheritance allowed at class level in PHP?

OM The Eternity picture OM The Eternity · Apr 22, 2010 · Viewed 14.6k times · Source

Is Multiple Inheritance allowed at class level in PHP?

Answer

Gordon picture Gordon · Apr 22, 2010

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: