What the…?> PHP and unwanted whitespace

February 18th, 2009

While working with some older PHP projects we’re migrating to our servers for some clients, I’ve run into a number of “unwanted whitespace” errors in PHP code. Unwanted whitespace can cause header output errors when they proceed a header call, or causing binary files loaded with readfile to break.

Typically, the cause of these errors has been the use of ?> followed by one or more whitespace characters. The extra whitespace was either added by the original author (and overlooked thanks to a low error_reporting level) or by a none-too-helpful FTP client.

After spending too long hunting down the whitespace (made necessary by the use of unnecessary code), I Twittered about the problem and a deluge of discussion followed.

Tradition and Convention vs. Need

According to the PHP manual on the topic of instruction separation, the use of ?> at the end of a file is completely optional. That said, the use of ?> has been standard fare for decades. At this point in history, most of us are so used to seing it dangling uselessly at the bottom of our code, that removing it feels painful or even dangerous.

Personally, I’d never thought to question it’s existence until I read the Doctrine ORM for PHP coding standards. Coding standards typically consist of a four spaces vs. tab debate, where one should put one’s curly braces, and class naming conventions. When I read Doctrine’s, I was surprised to find them start out with the requiring that ?> not be used at the end of files.

Since then, I’ve found other projects that require it be left off and, most recently, spent hours frustrated by the fact that someone before me didn’t leave it off.

Necessity, the Mother of Invention Convention

There seems to be growing movement among projects to drop the use of ?>. Most PHP coders, however, aren’t a part of those project. Many of us stumble across these things by accident, and overlook them as an oddity of a particular project (as I originally did with Doctrine) rather than a best practice for all PHP code. My hope is that my Twittering about it, this blog post, and subsequent debate/promotion/usage of the practice will save us all time down the road.

Discontinuing the use of ?> where it’s not needed is one way we can make the world a better place. No longer using PHP 3 and 4 and moving to PHP 5 would also help, but that’s another blog post.

Together toward the Future

December 11th, 2008

My vision for the future of the web (which I’ve been quite on for too long now) matches up with Google’s in many ways. That said, I’d be saddened if the only way to a better future went through the doors of a single company.

What’s needed is an ever increasing use and creation of open standards so we can all move up the innovation ladder or at least make that forward momentum generally available.

Perhaps the Cloud computing “movement” presents this opportunity in some ways. Tim Bray’s thought that PHP’s ubiquity may help this hope may point to a broader way forward–especially when it plays well with other languages via extensions and remote data stores like CouchDB and other web services.

BigBlueHat’s role in this will hopefully continue to increase. We’re doing things “here and there” at the moment as we continue to bootstrap our way to a successful CMS market share. In the future, though, we hope to give more, participate in more, and promote more of what we believe the web should be.

Help BlueInk win a Crunchie

December 10th, 2008

Sure we’re small, rural, etc, but here’s a shot at helping put our little company and/or product on the map. If you’ve used BlueInk, and believe it’s worthy of the Best App Award, we’d love to have you cast your vote.

If you’ve not yet tried BlueInk, we’d at least like to have you check it out at the BlueInk Demo Site.

Thanks in advance for whichever you have time to do.

php|works 2008

November 13th, 2008

php|works 2008 just began this morning. The keynote on open source product management is off to a great start.

If you’d like to follow the fun, check out the BigBlueHat Twitter feed or search for the #works hashtag.

Good times at Tech After 5

October 23rd, 2008

Every month the GSATC puts on a thing called Tech After 5. If you’re in the technology field (or service it as a lawyer, doctor, etc), it’s one of the best opportunities to do some free networking in the Upstate South Carolina area. And, as you can see in the photos below, they offer free food and intelligent conversation:

© 2007-2009 BigBlueHat
Close
E-mail It