Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Another Inheritance Question

From a quick Google search and a the wikipedia article on Multiple Inheritance, which quotes:

Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass.

I understand that PHP doesn't allow multiple inheritance. What I can't find a clear answer on, however, is whether it allows more than one class to extend a superclass. Example:

class a {}
class b extends a {}
class c extends a {}

In terms of what I'm trying to do, I'm making an RPG and want a 'generic' character class to include all the methods and properties that make the template of a character. Then I want classes to include specifics for each type of character (warrior, mage, etc), such as stats modifiers and special attacks.

Is this possible?

like image 479
Saladin Akara Avatar asked Nov 26 '25 18:11

Saladin Akara


2 Answers

Yes, it's perfectly possible. The entire purpose of inheritance is that multiple children can inherit common functionality from a parent.

like image 101
deceze Avatar answered Nov 28 '25 07:11

deceze


Yes, multiple classes can extend the same class, per your code example.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!