Multiple Inheritance suddenly more easy in PHP (than in C#)

Nor C#, neither PHP supports multiple inheritance, but in both programming languages there are workarounds. A nice article for simulated multiple inheritance in C# you can find here http://www.codeproject.com/KB/architecture/smip.aspx, and in PHP here http://www.serversidemagazine.com/php/how-to-inherit-from-multiple-objects-workaround/.
However, today I realised that none of the problems that can be caused by strong-typed programming languages in multiple inheritance can ever be found in PHP (doh!), which is a weak-typed programming language. Let me show you why.
Since declaration type doesn’t exists in PHP, you can’t have a construction like this:

BClass $var_a = new AClass();

instead, the correct syntax in PHP is:

$var_a = new AClass();

So keeping this in mind, in PHP if two classes BClass and CClass redefine a method m1() from AClass, and DClass inherits from BClass and CClass,

then you’ll never have to worry about constructions like:

CClass $var_d = new DClass();
$var_d->m1();

..because in PHP they simply not exists :) Anyway, it would be interesting in the future to see in PHP construction like in JavaScript: BClass.prototype = new AClass();

Comments are closed.