How to check if your code is compatible with PHP 8

10, February 2022

PHPCs can be used to check if your code base is compatible with a different version on PHP. This is very handy if you want to check if your project can be upgraded to PHP 7.4 or 8.1

Install

First install PHP_CodeSniffer if you haven't yet done so

composer global require "squizlabs/php_codesniffer=*"

Then install php-compatibility

composer global require "phpcompatibility/php-compatibility"

You may need to set the PHP_CodeSniffer config path to use PHPCompatibility

phpcs --config-set installed_paths /path/to/PHPCompatibility

Usage

phpcs -p ~/path/to/project --standard=PHPCompatibility --runtime-set testVersion 8.1
  • -p = The path to the project
  • -standard = the check to run
  • --runtime-set = Options to set at run time
  • testVersion = The version of PHP to test against. In this case PHP 8.1

More options can be found in the GitHub documentation

Peter Fisher Contract Web Developer

Peter Fisher is a UK based PHP contractor with 20 years experience in web development He can be hired to work with PHP using Symfony or Laravel or Flask and Django with Python.