Prototype based object oriented programming in PHP

The other day I’ve found this interestingly controversial submission on reddit and I must admit that after taking a quick look at the code, I ran of for some eye bleach to erase that image from my mind.

While I know that the author had the intention to experiment with the idea of Prototype based inheritance, god forbid something like this goes into a production environment… and trust me, with enough exposure someone will use it.

I’ll gladly share one of my principles with the author:

If you are fighting the language (or framework, library), it means it’s time to ditch it for something else instead of forcing it to work your way… that never turns out well.

Wanting this to not come out as a rant about somebody else’s code (no one likes that), I will instead suggest an implementation that is somehow less obtrusive towards the language, but still an experimentation idea.

Not being familiar with Ruby, I’ll show a prototype inheritance model based on the JavaScript language. Although io‘s implementation would possibly look cleaner, I’m aiming for a more common ground given almost every PHP developer is familiar with JavaScript.

Filed under Challenge, Code

blog comments powered by Disqus