talira

PHPCompatibility

PHP_CodeSniffer sniffs that check PHP code for cross-version compatibility

open sourceLGPL-3.0-or-laterfree

PHPCompatibility is a set of sniffs for PHP_CodeSniffer that checks PHP code for compatibility with higher and lower versions of PHP. Set a testVersion (a single version or a range) on the command line or in a ruleset, and it reports features that don't exist or behave differently in those versions. It aims to cover every compatibility change since PHP 5.0 up to the latest release, and framework, CMS and polyfill rulesets build on it.

Problems it solves

  • check whether my PHP code will run on a newer PHP version before upgrading
  • find PHP features in my code that an older PHP version doesn't support
  • lint a PHP codebase for version compatibility in CI

Features

  • sniffs that flag PHP features unavailable or changed in a chosen PHP version or range
  • testVersion set per run or in a custom ruleset
  • consistent results whichever PHP version runs PHP_CodeSniffer
  • framework, CMS and polyfill specific rulesets that extend it

Limitations

  • Coverage of PHP compatibility changes isn't complete, and changes before PHP 5.1 are only patchily covered.1
  • Needs PHP 7.2+, PHP_CodeSniffer 4.0.2+ and PHPCSUtils 1.1.2+.1

Alternatives

The same job

These do what PHPCompatibility does.

  1. PHP Parallel Lint Checks the syntax of PHP files in parallel
  2. PHPMD PHP Mess Detector: finds bugs and code smells in PHP
  3. WordPress Coding Standards for PHP_CodeSniffer PHP_CodeSniffer rules that enforce WordPress coding conventions
  4. ESLint Find and fix problems in your JavaScript code.
  5. PHP_CodeSniffer Detect and fix coding standard violations in PHP
  6. PHPCompatibilityWP PHPCompatibility ruleset for WordPress projects that skips WordPress's own polyfills

Compare PHPCompatibility with the top 3