0

i have the following simplified code

class A{}
class B extends A{}
class C extends B{}

It is working perfectly and everything is ok, but i wanted to make sure that it's not bad practice so i googled "multiple inheritance in php" and was surprised that many posts i read said that multiple inheritance in php is not supported and the alternative is traits.

So i doubted my definition of multiple inheritance and googled a good example about it and this Multiple Inheritance: What's a good example? came up, and it is in fact exactly as what i was doing but in a different context.

can someone shed some light on the matter?

3
  • 1
    Because it's not multiple inheritance. It's just two-levels inheritance, but each class has only one parent Commented Aug 11, 2014 at 12:27
  • You just created a grandchild class, not multiple inheritance. Commented Aug 11, 2014 at 12:28
  • @ChristopherLamm can you please take a look at the answer of the question i linked? Commented Aug 11, 2014 at 12:35

1 Answer 1

2

You are not using multiple inheritance, you pasted an example of polymorphism.

Multiple inheritace = multiple parents

class Animal {}   
class Mammal extends Animal {} //single inheritance
class WingedAnimal extends Animal {} //single inheritance
class Bat extends Mammal extends WingedAnimal {} //multiple inheritance, not supported by PHP.
Sign up to request clarification or add additional context in comments.

3 Comments

then what's with the answer of the question i linked. @Naktibalda
so the answer in the link is not correct right? @Naktibalda
Answer in the link is correct. But there is no multiple inheritance in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.