0

We know that PHP5 or later allow OOP but not support multiple inheritance like C++ Does PHP7 supported Multiple Inheritance?

amir mehr
  • 25
  • 1
  • 4

2 Answers2

0

From the manual:

A class can inherit the methods and properties of another class by using the keyword extends in the class declaration. It is not possible to extend multiple classes; a class can only inherit from one base class.

akond
  • 15,865
  • 4
  • 35
  • 55
0

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

armyofda12mnkeys
  • 3,214
  • 2
  • 32
  • 39