There are a lot of nice packages that we can use in our PHP-based projects and if you’re using Composer or GrumPHP, PHPCompatibility is one that I recommend including your projects especially if you’re writing code for something that’s going to run across multiple versions of PHP (that is, on hosts that offer different versions).
This is a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.PHPCompatibility Repository
This is something that be installed within composer and it’s something that I recommend for people writing code for WordPress because of how much variation exists within our hosts.
Occasionally, though, you may see a problem like this:
And if you run
$ phpcs -i you may get a message that’s unclear.
Fix the Referenced PHPCompatibility Sniff
Specifically, if you run that command, you may see this:
Odd, right? But there’s a simple fix and it has to do with updating the post-install and post-update script commands that Composer offers.
To that end, we can employ the same techniques to ensure that PHPCompatibility properly works if you ever see the message. Simply update your
composer.json to look like this:
Of course, your mileage will vary depending on your actual set up but the gist of the commands should solve the problem.