Add new comment
by Lorna Mitchell
Things are a-buzz in the Drupal community, with a major new release on the horizon: Drupal 8. It heralds many excellent features of course, but one major change is that Drupal 8 will require PHP 5.3 as a minimum platform. PHP 5.3 adds a ton of goodness for Drupal and other PHP users (see "Feature Heaven" below), but there's even better in store for you in PHP 5.4 (faster) and 5.5 (more efficient)! The Drupal project is in a great place using PHP 5.3, but if you're wishing that PHP would be faster, have more features, or make better use of your hardware, the next versions of PHP have already got those features ready for you!
PHP 5.3: Feature Heaven
The reason that so many frameworks and libraries now require PHP 5.3 is not because it's “the new shiny” in PHP, but because it's got absolutely killer features. Many of these are things that, from my privileged standpoint of having PHP 5.4 as my regular platform, I literally can't imagine living without.
Namespaces / PSR-0 / Composer - PHP 5.3 brought us namespaces. I now feel the same way about code without namespaces as I once felt about code with
register_globals enabled ... How can you ever keep things tidy? Namespaces facilitate all kinds of other goodness in PHP-Land too: We can pick and mix bits of multiple frameworks, and our own code, safely into a single project. There's even a standard way to do that with PSR-0, the autoloading standard adopted by most PHP projects, and a dependency management tool that builds on those standards, Composer.
For Web Developers - All the features I've mentioned have been aimed more at core developers than at you, the talented and efficient web developer. But PHP 5.3 also introduced changes that are useful for all of us. For me as a consultant and occasional DevOps person, that especially includes the
E_DEPRECATED flag. This is an additional error reporting constant, which can be used to give notification of all features used that will be removed in a future minor point release of PHP. So, if you turn this on for any PHP 5.3 version, this level of error will be generated for all features which will be removed in PHP 5.4. We removed lots of pointless features in PHP 5.4 – such as the y2k_compliance configuration directive. Is anyone worrying about the year 2000 anymore? Similarly, any language features which will be removed in PHP 5.5 are marked as deprecated in PHP 5.4. Using this feature makes it much easier to move an existing application between platforms. From PHP 5.3 and later, you can (more) safely upgrade your platform without unexpected breakages in your application.
So why would you upgrade between PHP versions if you aren't going to use new features?
PHP 5.4: Same Again, But Faster
PHP 5.4 isn't new by some metrics – it was released in March 2012 – but it's probably new to most Drupal users since Drupal hasn't required a newer platform until now. This can lead to lag-thinking that we don't “need” to upgrade. The best new feature of PHP 5.4 is this: PHP 5.4 is faster. I blogged about this in detail, but I'll summarize for you here with a graph comparing PHP 5 version performance:
￼Faster / Reduced Memory - The time axis shows how long, in seconds, each version took to run a particular benchmark. Moving an existing application from PHP 5.2 to PHP 5.3 is going to give you a performance boost. By the time you get that same application onto PHP 5.4, it'll be performing twice as fast as it was on PHP 5.2. Of course, your mileage may vary between applications, but object-oriented applications will see the biggest performance improvement. As an added sweetener, the memory footprint is reduced in PHP 5.4 also; this is difficult to benchmark but I'm hearing anecdotal evidence of anything from 20% to 30%. All this in return for an upgrade to software that is already free, and will probably run on your existing hardware!
Short Array Syntax / JSON / Traits - PHP 5.4 does also have new features that I think are really valuable. We have a short array syntax which seems rather inconsequential until you get used to using it and realize how much you miss it when you work on a legacy system. There's a
JSONSerializable interface, to allow an easy way to tell objects how to handle themselves when we convert them to JSON. We also have traits, which allow you to put the same method (or a group of methods) into any number of unrelated classes – but only declaring the functionality once. This is such a supremely useful feature that quite a few of the frameworks are already including traits. Unfortunately, PHP 5.3 users can't make use of this feature and therefore the code will never be auto-loaded or parsed: PHP 5.4 users can just get on and use it!
PHP 5.5: The Future and Beyond
Welcome to the current stable version of PHP: 5.5! We have everything you already had, but it's better, it'll be supported for a good while longer, and you need a bit less hardware to run it on. Upgrading is a matter of pride, not pain. With many thanks to PHP core contributors everywhere, enjoy the future – it's here already!
To put that in context, PHP 5.2 was declared “end of life” in January 2011, and PHP 5.3 will follow in June 2014 – probably not too long after the Drupal 8 release onto this “new” platform. The “end of life” status doesn't mean you can't use those versions, or that they're suddenly broken, but it does mean that they won't be updated, even for security fixes, by the PHP team after that date.
To be fair, according to W3Techs, of all websites running PHP 5; 51.9% use PHP 5.3, while PHP 5.2 still makes up 38.9% (watch for this to jump when Drupal 8 sites start proliferating). Sites using PHP 5.4 account for only 6.8% of PHP 5 sites online and PHP 5.5 only 0.2%. For perspective: PHP is used by 81% of all websites, some version of PHP 5 is used by 78.7% of all websites as of September 9, 2013.
In summary, the Drupal project has done well to upgrade to PHP 5.3. As soon as you're still looking for faster, more feature-rich, or more efficient PHP, the next versions of PHP have got those features ready and waiting for you!