Possible duplicate:
Is class level multiple inheritance allowed in PHP?
So, I know that in PHP multiple inheritance is not directly supported (I assume this is the case in many other languages ββsuch as java, for example). So we are doing something like:
class A extends B implements C, D
and now from PHP version 5.4 , I think we have traits , which bunches functionality together.. and can be used several classes.
Now my question is, why cannot there be multiple support for inheritance in such languages?
I mean something like:
class A extends B, C
I read several articles on the Internet where people tried to explain why it was difficult to implement in this language, but either they were too technical for me to understand or not seem like a good enough argument. Can someone describe in simple terms why it is difficult to support multiple inheritance in these languages? It would be great if you could include the PHP context, because that is the language that I know best.
I always think that this may be due to ambiguity (a problem with a diamond, etc.), but it can be easily handled by some mechanism of the namespace tokenizer when declaring a function. I think I know. means that the language may need to override the same function twice (for example, how overloading works in Java)
<?php class A{ function __construct() { } function ambiguous_fn() { echo "This function is ambiguous"; } function fnA() { echo "This is function A"; } } class B{ function __construct() { } function ambiguous_fn() { echo "This function is ambiguous"; } function fnB() { echo "This is function B"; } } class C extends A,B{ function __construct() { }
I mean a real object that imitates perspective, at times I think that pure multiple nature will be such a big help. I know that one of the arguments is that "The use case for multiple inheritance is very small and can usually be resolved using multiple interfaces, mixins, etc." But in fact, there should be a more compelling reason why the language developers did not bother to implement pure multiple inheritance that one might think of.
Do I really not understand the point here? Can someone shed more light on this?