dagfinn | 25 August, 2005 22:56
Having immersed himself in some hideously coded PHP application, Alan Knowles lists six deadly PHP sins in a recent and very illuminating blog entry.
Maybe it just wasn't present in that particular example; for whatever reason, he didn't mention my particular favorite: the script include.
In PHP, it's possible to use an include file that only contains PHP code and just executes the code at the point where it's included. Typically, the include file uses global variables that are set in the including file.
This resembles a function call, but it's less explicit and harder to re-use.
In fact, global variables can hide deep inside a nested set of included files and be re-used in another file at another level of deep nesting. That can make it all but impossible to track down where a variable originates.
dagfinn | 25 August, 2005 15:49
Inspired by a thread in the Sitepoint PHP application design forum, I went looking for some open source blogging software that was reasonably well designed. The reason was that I wanted to be able to modify the application if necessary but without having to enter "the heart of darkness"--trying to decrypt the kind of obscure code that is all too common in PHP applications.
My approximate minimum requirement for a good design is some kind of object-orientation. To test that, I downloaded about 30 different applications and searched the PHP code for the keyword class. pLog was the winner; that's why I'm using it to write this.
WordPress looked promising from the numbers I got at first, but from what I'd heard about it, I was skeptical. Checking it out, I found that the vast majority of occurrences of class were actually CSS classes.
After correcting that, my list looks like this:
917 plog-1.0
135 b2evolution
86 serendipity
57 wordpress
32 easymoblog-0.4.1
24 redblog
24 bblog
22 bdblog
11 hold
10 complete
7 pixelpost_1.4.2
6 bmachine
6 birdblog_1-3-4
5 rws_1_0
2 esqlanelapse2-BETA7
1 webspotblogging
1 phase
The names may be somewhat mysterious, since they're derived from the downloaded file names. WordPress is still getting unfair positive attention, since some of the occurences of class are actually a variable name $class. I'm sure there are other sources of error as well, and there may be other apps out there that I've missed. But the results are interesting.
| « | August 2005 | » | ||||
|---|---|---|---|---|---|---|
| Su | Mo | Tu | We | Th | Fr | Sa |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||