4 things that happened in PHP while you weren’t looking
PHP gains some modern features as it heads to a 7.0 release.
I think most programmers have come into contact with PHP at some point, editing a WordPress plugin or getting PHPMyAdmin running on a server. We think we know what PHP is, but the language has been very quietly growing up over the last few years, so here’s some headlines that you might have missed.
Upgrading is easy
PHP has always had frequent patch releases, but now its minor releases are approximately annual. This means that the differences between the versions, and therefore the painful experiences of an upgrade, are much reduced. It also means that there’s probably a relatively new version available at the time when a distro is rolling its new release.
PHP has also developed much greater consideration for its users when upgrading. From PHP 5.3 there is an error_reporting level,
E_DEPRECATED, which will log any features you are using which will be removed in the next version of PHP. Nothing gets removed in a minor version that wasn’t already planned to be removed before the release of the previous minor version — so fewer surprises for those of us in userland.
PHP has a built-in server
It’s for testing use only (it’s single-threaded), but if you want to give a PHP web application a whirl, you don’t need to configure a new vhost or anything else. You can simply start PHP from the command line with the -S switch and it will serve from the local directory as its webroot.
php -S localhost:8080
With this running, you see the logs in your terminal and you can request http://localhost:8080 to see the application. I’d recommend using a
php.ini file with it (use the
-c switch); PHP ships with a good
php.ini-recommended that you can use and it’s much less weird than just letting it fall back to the language defaults. Other tricks you can play with this tool:
- specify a webroot in a different directory: this is useful if you’re running the server under supervisord or otherwise from a different location
- add a routing file that can be used to do the job of an apache
- bind to 0.0.0.0:8080 to make your application visible to other people on your network, I find this useful for letting managers take things for a spin
Personally I use this tool when I’m working with one-off scripts for a book chapter or conference talk. I also use it as a migration tool. When upgrading to a new version of PHP, I compile my target version without installing it as the main PHP on my machine, then use this server to try my application on the new version of PHP. It’s a good first step on an upgrade path (second step — I lint check first!) to knowing how much work there is between you and your application running faster and more securely on a newer version of PHP.
PHP has dependency management
This is long overdue in PHP but it’s here and it’s fabulous. PHP’s dependency management tool is called Composer and it’s a standard ingredient in all modern web applications. When PHP finally acquired namespaces (way back in version 5.3), it became much easier to pick and mix code from a variety of frameworks and libraries in a single application. Now our ecosystem looks much more like you’d expect with many small tools building on one another and end-user applications that specify what they need and automatically pull that all in on each platform.
I once wrote that PHP was the land of a thousand frameworks and those days are long gone. Now we have an open market for great library providers and far less duplication between them all, Drupal uses elements from Symfony, and we’re all one big happy family again.
PHP 7 will ship this year
Current stable PHP is 5.6, so the next version is obviously… PHP 7! Actually there was once a PHP 6 that never made it to stable (most of it ended up in PHP 5.3), but is so different from our future that we decided the naming clash was hopelessly confusing. So like all good scripting languages, we’ll never release a version 6, but PHP 7 will be coming late in 2015.
What’s in PHP 7? Great question! So far all I’ve managed to find is a lot of people gibbering about how much faster it is, which given the huge improvements in performance in recent versions of PHP, is pretty exciting in and of itself. As for the features, plenty of ideas are in the mix — look out for more news as we start to release alpha and beta versions later in the year.
Editor’s note: If you’re excited about where PHP is heading and would like to get beyond the basics or update your current PHP skills, check out Lorna Jane Mitchell’s Intermediate PHP video training course.
This post is part of our ongoing exploration into the explosion of web tools and approaches.