Get ready for PHP 7.2
PHP 7.2 is around the corner, and shall be out soon, thanks to the hard work of Remi Collet (@RemiCollet), Sara Golemon (@saramg) and countless others that run tests and submit bug reports. PHP 7.2 is already RC6, and the documentation has even been updated : it is high time to get ready for PHP 7.2.
We have been hard at work, at @Exakat, to prepare the migration analysis. This is our take on this upcoming task.
Let’s review it quickly :
This table breaks down the various aspects of the migration steps, and tells what tools you can use to get ready :
- Know : your own knowledge of the code. This is the master tool for a migration, so don’t understimate it. It is error prone, and it usually lack comprehensiveness, so do not use it alone. But anything you already know is code that will be fixed first. It’s also great on code-wide features, like a new extension.
- Lint : linting is using ‘php -l’ on every command in your code. Do it as daily hygien, and avoid commiting uncompilable files. It was so useful when moving to PHP 7.0, but sadly, it’s very quiet for PHP 7.2.
- Static analysis : it’s very comprehensive, but lack focus and ability to understand general notion. It works best with your own knowledge of the code, and it may also help to start using new features.
- Unit test : well, once you have done everything you can, then it is time to run the code. The first step is to run it on unit tests (or any kind of test, really), and target anything that fails, but was not failing with PHP 7.1.
- Log : when all the UT pass, then, you may try in production. Good news is that PHP 7.2 is deprecating many features, and generating a lot of warnings, but still processing the code as it was before. So, crank up that error_reporting, and watch the logs for anything that was not caught by the previous solutions.
Here is the table, with the sum. Links are provided to the docs for more information.
Red features are backward incompatible, and may prevent your from migrating.
Light green are new features, that can wait for full migration before being put to use : just don’t forget them once you have a new stable code base.
Check your migration status with Exakat
You can check your code and make it ready for PHP 7.2 : Exakat comes with a full report for PHP 7.2, as well as reports for previous versions.
Each analysis has more details of what issue was detected, where it appears in the code.
You may even start checking for PHP 7.3 now : there are new features already available, like PCRE2 support for the ext/preg extension.
Run exakat on your code and get ready
You should be ready to ready your code’s audit under 15 minutes :
- Choose your installation from bare metal, docker or Vagrant.
- Php exakat.phar init -p myCode -R myRepository
- php exakat.phar project -p myCode
- Read the report.
Happy PHP code reviewing
Keep your code up to date with Exakat’s audit : take advantage of the safer and more modern PHP platform. And make those statistics go up everyday !