views:

31

answers:

4

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?

+2  A: 

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

Adam Backstrom
+1  A: 

This is the foundation of OOP. It's possible.

Chris Dennett
+2  A: 

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

deceze
Awesome, thank you. I wasn't sure with all the talk of multiple inheritance, haha.
Saladin Akara
+1  A: 

Yes, any class can extend a base class. In your example, it just isn't possible for class c to extend both a and b.

Joel Etherton