Broken static methods in PHP make me sad.
A few weeks ago, I tried implementing ActiveRecord in PHP. What a fool I was. Consider the following:
Code (php)
-
-
<?php
-
class ActiveRecord {
-
return "SELECT * FROM " . self::$table;
-
}
-
}
-
-
class User extends ActiveRecord {
-
}
-
?>
-
Sadly, User::findAll() returns “SELECT * FROM NOTABLE”.
I guess in order to implement ActiveRecord in PHP, you need to use some sort of combination of Singleton and Factory patterns? Gross.
Add this to the list of things that make me angry when I work in PHP. (The first item in that list is $a ||= “default” doesn’t work. Bah!)
1 Comment