Check PHP compatibility

php web test qa quality assurance
Reading time: 2 minutes, 0 seconds

In life cycle of a project, you must upgrade the server where it installed. During this upgrade, PHP version can be upgraded. A legitim question is if the project is ready to run on the new version of PHP. This question of quality assurance can be integrate to your continuous integration process during all the life cycle of the project.

Check with Code Sniffer

Code Sniffer (PHPCS) is a tool of quality assurance (QA), it tokenizes PHP, Javascript and CSS files and detects violations of a defined set of coding standards.

By default, PHPCS doesn't know a standard to PHP Compatibility. To cover this case, you can use PHPCompatibility whose define the standard to use.

Install Code Sniffer

There are three methods to install Code Sniffer:

  • Download PHAR files
  • Pear installation
  • Composer installation

For our case, we prefered Composer installation:

composer require "squizlabs/php_codesniffer=*"

Install PHPCompatibility

After PHPCS installation, you can add your standards in /Standards folder located in /vendor/squizlabs/php_codesniffer/CodeSniffer/Standards. To install PHPCompatibility in Standards, run:

git clone

To check if the new standard is successfully installed, just run the command:

./vendor/bin/phpcs -i

You must show all installed standards. You should see PHPCompatibility among them.

The cloning of GIT repository can generate a wrong directory level. You can fix this with following command:

phpcs --config-set installed_paths /vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/PHPCompatibility

Checking compatibility

To check compatibility we can run the follwoing command:

./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.1 <path>

With this command you checking compatibility in PHP version 7.1 on the folder or file defined in <path>

The output of the test will similar to:

To test backwards compatibility, it is advisable that you execute PHPCS on the latest PHP version available.

Naturally, you can add all others PHPCS options. For instance, you can limit the test to files with .php extension. To do this, complete the earlier command:

./vendor/bin/phpcs --standard=PHPCompatibility --extensions=php --runtime-set testVersion 7.1 <path>

To ignore files or folders, you can use the option --ignore=vendor,cache.

Next Post Previous Post