PHP / Zend / www.elcome!

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();


Categorised as: PHP / Zend / HTML / JS


4 Comments

  1. [...] wrote yesterday an article introducing Cosmin’s blog. His most recent article is on multiple inheritance and how easy it would be to implement that into weakly typed like PHP. [...]

  2. This blog post is excellent probably because of how well the subject was developed. I like some of the comments too though I would prefer we all stay on the subject in order add value to the subject! Plagiarism detection

  3. Cheers for the info, and your web-site truly looks fantastic. Just what wp theme are you using?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>