giles
giles

Reputation:

inheritance from two parent classes

I read about this ages ago but never tried it now I can't remember if this is possible or not. Is it possible to extend a class from two parents on php5 e.g.

class_d extends class_c and class_b

moreover can you do this if class_c and class_b are themselves extended from class_a ... so you get something like this

                          class_a
                  class_b          class_c
                          class_d

Upvotes: 4

Views: 1667

Answers (2)

Loki
Loki

Reputation: 30960

What you want is called multiple inheritance. It doesn't exist in PHP.

Alternatives exist though: Composition, A parent could inherit the other, mixins and maybe more...

From: http://www.phpbuilder.com/board/showthread.php?t=10351110

Upvotes: 3

StingyJack
StingyJack

Reputation: 19479

multiple inheritance (what you are looking for) is not supported in PHP.

You may want to check out composition (where one class contains an instance of the parent) or even interfaces if it applies specifically to your situation.

Upvotes: 3

Related Questions