Strange days, strange code

There is this big opensource blogging platform. It’s commonly used as a complete CMS solution to many websites. Even this site uses it. Yes, I’m talking about WordPress. Currently WordPress is hosting over 70 million websites. When you are talking about an ammount that massive you would say the source code by now woud look all tidy and neat. Well, I suggest you brace yourself.

if ( !isset( $HTTP_RAW_POST_DATA ) ) {
 $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );

if ( isset($HTTP_RAW_POST_DATA) )

Two things that stand out from the crowd here. The first is the space after $HTTP_RAW_POST_DATA in the first if-statement before the closing parenthesis. Of course, you have a lot of developers working on this. Different people have different habits. Things like this are impossible to prevent. At least, you would think. But wait, aren’t there solutions to this problem? Of course there are! PHP CodeSniffer for example. This tool analyses PHP-code based on a set of pre or user defined rules and gives back a report containing remarks about codestyle violations. It even chains with SVN’s pre commit hook, so rogue developers won’t be able to commit their code!

Second thing is this: What the hell is the second if-statement about? After the first one there is no way that $HTTP_RAW_POST_DATA is not set. No way. Just not. It is not possible that the if-statement evaluates to false. It is always true. Always. If $HTTP_RAW_POST_DATA was not set before the first if-statement then it surely was after the first if-statement. That’s another wasted CPU cycle (on 70 million blogs) right there. Well, at least that didn’t type a space here.

This is just one of the many examples of strange code in the WordPress source code. Don’t get me wrong, I love the application. It’s fast, easy to work with and handy to use. But there are a few things that are just a bit weird. Maybe it’s about time to shake of the weirdness when you are serving 70 million website. Thats all.