PHP 7 is well on its way. RFCs are being implemented and polished, projects are being tested, libraries upgraded. Extensions are being modified, and the word is spreading. All that remains is getting the shared hosts on the upgrade bandwagon – the arguably most difficult part of improving the global state of PHP. In this article, we’ll take a look at some of the most important PHP 7 related resources and tips you should go through in preparation for the new version.
Image via Vincent Pontier
Some months back, Rasmus Lerdorf created and uploaded a Vagrant box for testing on PHP 7. This box can be downloaded from Github. In case the instructions are confusing (they shouldn’t be), see Rob Allen’s post. The box boots up in minutes and has not only PHP 7 enabled, but can also very easily update to the most recent version of PHP 7, and to dozens of other PHP versions.
The box features a
newphp command which instantly replaces the PHP version currently in use with another binary, pre-compiled on the box. So for example, typing
newphp 55 in the box will switch from PHP 7 to PHP 5.5., allowing you to quickly run your code in another version. What’s more, each version has its own PHP extensions folder, so you can easily compile and install new extensions – they all end up in the right location, and won’t conflict with other PHP binaries.
In a way, it’s similar to DUnit which uses Docker containers to fire up different PHP versions for you to test on.
For more information and some interesting benchmarks of various CMSes from Rasmus himself, see this talk slideshow of his.
Other boxes and Testing
Use Rasmus’ box above, or if you’re using PuPHPet, they recently added PHP7 support. There are some caveats, but in general, it should work. Vaprobash and Phansible aren’t there yet, but here’s hoping.
If you’d like to roll your own, this Ansible playbook for Ubuntu / Debian might help, or just go full-shell and follow these instructions – the post also has tips on writing tests for the actual PHP build, so you can contribute to the language itself!
If you don’t feel like firing up VMs, you can use some of the official nightly builds (also supported via Docker) from Zend, but it’s also quite easy to do in Travis, which now includes PHP 7 in its builds. In fact, the phpleague/skeleton has this built-in. Just remember – if you’re using the Travis results to power Scrutinizer’s code analysis – you should allow failures on PHP 7 and maybe even make sure the report for PHP 7 doesn’t get submitted at all.
Testing for PHP7 on Travis not only makes sure your code works on the latest nightly without forcing you to manually update your PHP7 build, but also gives you some street cred to brag with – “My code is PHP7 ready!”.
Libraries, packages and apps aren’t the only that need testing, though. Like the March Newsletter said (to which you can subscribe via this form, btw), extensions are on the front lines. PHP7’s new extension API is different enough from the old versions that several extensions will need extensive rewrites to remain compatible.
With that in mind, the gophp7-ext page has been set up to ease the transition for most extension developers.
Hopefully, this will make it easier for projects like Zephir and the newly released Phalcon 2 to become 7-friendly as soon as possible (as the Phalcon team says, they’re already looking at the necessary PHP7 upgrades).
If you develop PHP extensions (maybe you started after reading some of our tutorials?) or know people who do – point them to the GoPHP7-ext page and have them bring their code up to par. If you can get them to write about the process, documenting the changes that needed to be done, please do point them my way and we’ll publish their findings (and pay them handsomely for them), so others can benefit from learning about the process.
Finally, let’s list some of the most important reading resources you should go through to get on top of the changes that are coming up.
Phil Sturgeon got the ball rolling with his post about the PHP7 feature freeze and the current state. It lists some of the more important RFCs, but you should look below to Davey’s post for a more detailed overview.
What to Expect is the first post you should read. It’s a two-part series from Davey Shafik, which explains the upcoming changes in a down-to-earth way. It’ll list all the important accepted RFCs and display demo code for each, so you can see how they might affect your workflow on practical examples.
PHP7 at a Glance from none other than Zend is yet another excellent overview. It features all the RFCs listed with their potential impact on a developer’s life plus the chances of BC breaks (there are some in edge cases, but none certain).
Comparing PHP7 and Hack type systems implements the same functionality with type hints (now that they’re coming to PHP) in both PHP7 and Hack. The differences may surprise you, and might be something worth keeping in mind. The post has been discussed on Reddit.
If you’re confused about the strict types, this still relevant post breaks it down.
- PHP7 Revolution – Return Types and Removed Artifacts is our own preliminary look at PHP7 from way back when the announcement was still hot off the press. (Link added May 14th, 2015)
- Zend put out this impressive looking infographic on performance. It doesn’t have the benchmarked source code or the environment details, though, so take it with a grain of salt. (Link added May 14th, 2015)
As you can see, there’s a lot of content to go through – and version 7 is still months away. We’ll be updating this list with new resources periodically, so make sure you check back from time to time – newly added posts will be put to the bottom of their respective list and tagged with the date of addition.
Do you know of any valuable resources we’ve missed? Want to write something for us? Let us know!
Bruno is a blockchain developer and technical educator at the Web3 Foundation, the foundation that's building the next generation of the free people's internet. He's also a DX person at Diffbot. He runs two newsletters you should subscribe to if you're interested in Web3.0: Dot Leap covers ecosystem and tech development of Web3, and NFT Review covers the evolution of the non-fungible token (digital collectibles) ecosystem inside this emerging new web. His current passion project is RMRK.app.