Everyone knows I am not too fond of OOP. And yet, I had some role in crafting DBTNG. I now admit: DBTNG in its current implementation is a mistake. Making the stream wrappers a class -- although PHP mandates that -- is a mistake.
Daniel Kudwien's complaints on the CDN post dawned this on me. While I was always complaining of PHP's inability of adding a method run-time, the problem we face is that you can't replace one either. So if you do what I did in the previous post, namely use the hook-alter patten (already an addition to PHP, I must say) to override the classname, that works. However, if two modules try to do this for two different methods, you fail.
Fail is the name of the game and this game is PHP. Here is Python:
x = 'test'
print self.x + 'foo'
print self.x + 'bar'
// We need the test.foo method to do something else.
test.foo = bar
this happily prints
class has fallen, the class is done and there is no way to add code (or modify code) that will access protected/private properties of that class. This is an iron wall that can not be breached by either the __call hack or closures (at least in PHP 5.3).
Drupal 8 should admit we made a mistake with Drupal 7, get rid of all this closed crap that in PHP is called OOP and work hard on making our fixes to the language (the hook system and more) even better to replace it. It was a very interesting attempt, let's abandon it, it does not work too well. Let's implement a working OOP system in PHP, using procedural notation if we must -- because there is no other way. Drupal rocks because it's flexible, because it's already addressing some of the PHP shortcomings and because it's fundamentally AOP instead of OOP. Let's continue going down that road we partially abandoned in Drupal 7 dazzled by the awfully limited OOP features of PHP5. OOP has it's place, yes. But the parts of OOP that made it into PHP are not enough for Drupal.
To be more concrete here, while addition was always possible via the hook system -- even if node module did not implement hook_foo_bar, foo module could just use
function node_foo_bar -- the modification was not (nicely) solved. Alters are some sort of a solution... but they are not exactly the same as replacement, as they are an addition step that allows changing stuff, it's not replacing a method/function/behaviour/whatever.
Ps.: Yes, Drupal 7 will be awesome nonetheless. Just we will hit walls which we could have avoided. We will make life harder than necessary. Let's face this and fix in Drupal 8.
Commenting on this Story is closed.