amitmerchant1990 / amitmerchant-dot-com-comments

1 stars 0 forks source link

this-is-why-php-dont-have-multiple-inheritance/ #101

Open utterances-bot opened 9 months ago

utterances-bot commented 9 months ago

This is why PHP don't have multiple inheritance — Amit Merchant — A blog on PHP, JavaScript, and more

In this article, I will discuss about why PHP don’t support multiple inheritance and how it has resolved this issue by allowing classes to implement multiple interfaces.

https://www.amitmerchant.com/this-is-why-php-dont-have-multiple-inheritance/

szymat commented 9 months ago

As you can see from the code, on calling the method greet() using object ClassC, it’s impossible for the compiler to decide whether it has to call ClassA’s greet() or ClassB’s greet() method. So, this is to avoid such complications, PHP does not support multiple inheritance.

From any problems with multiple inheritance you choose the one that can be fixed with like throwing exception?

I see your point, but I don't think thats proper argument. Other arguments and composition over inheritance I am all in 🙌

Gurusiddhayya commented 8 months ago

As you can see from the code, on calling the method greet() using object ClassC, it’s impossible for the compiler to decide whether it has to call ClassA’s greet() or ClassB’s greet() method. So, this is to avoid such complications, PHP does not support multiple inheritance.

Can you explain problems with multiple inheritance you choose the one that can be fixed with like throwing exception?