PHPackages                             phpcompatibility/php-compatibility - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. phpcompatibility/php-compatibility

ActivePhpcodesniffer-standard[PSR &amp; Standards](/categories/psr-standards)

phpcompatibility/php-compatibility
==================================

A set of sniffs for PHP\_CodeSniffer that checks for PHP cross-version compatibility.

9.3.5(6y ago)2.3k74.3M—2.6%204[86 issues](https://github.com/PHPCompatibility/PHPCompatibility/issues)[4 PRs](https://github.com/PHPCompatibility/PHPCompatibility/pulls)20LGPL-3.0-or-laterPHPPHP &gt;=5.3CI passing

Since Apr 4Pushed 1mo ago50 watchersCompare

[ Source](https://github.com/PHPCompatibility/PHPCompatibility)[ Packagist](https://packagist.org/packages/phpcompatibility/php-compatibility)[ Docs](http://techblog.wimgodden.be/tag/codesniffer/)[ RSS](/packages/phpcompatibility-php-compatibility/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (44)Used By (20)

PHP Compatibility Coding Standard for PHP\_CodeSniffer
======================================================

[](#php-compatibility-coding-standard-for-php_codesniffer)

[![Latest Stable Version](https://camo.githubusercontent.com/b9612288d338ff99b533911378e384b24eb07963777ae7ae4a91955b7bfde01a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870636f6d7061746962696c6974792f7068702d636f6d7061746962696c6974793f6c6162656c3d737461626c65)](https://packagist.org/packages/phpcompatibility/php-compatibility)[![Latest Unstable Version](https://camo.githubusercontent.com/36aaf6b5002a9c809356c5cef488554c466dd55b6d898f792039151ad2f2ee3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d646576656c6f702d6536383731382e7376673f6d61784167653d32343139323030)](https://packagist.org/packages/phpcompatibility/php-compatibility#dev-develop)[![Awesome](https://camo.githubusercontent.com/e3718252e9cb9d236e13f891808bc5861337368a897129bbdcb34f1c89ce1d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617765736f6d652533462d796573212d627269676874677265656e2e737667)](https://camo.githubusercontent.com/e3718252e9cb9d236e13f891808bc5861337368a897129bbdcb34f1c89ce1d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617765736f6d652533462d796573212d627269676874677265656e2e737667)[![License](https://camo.githubusercontent.com/409433b1096179d170709ed846fd91908b9a19d8b48a9729e054b4d42c433da6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f504850436f6d7061746962696c6974792f504850436f6d7061746962696c6974793f636f6c6f723d303061376137)](https://github.com/PHPCompatibility/PHPCompatibility/blob/master/LICENSE)

[![CS Build Status](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/basics.yml/badge.svg?branch=develop)](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/basics.yml)[![Test Build Status](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/test.yml)[![Coverage Status](https://camo.githubusercontent.com/04b0e54c6fadb9a9cacf9cb6916cbaa337d566cd81b25e434d63c3a9e235e7d9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f504850436f6d7061746962696c6974792f504850436f6d7061746962696c6974792f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/PHPCompatibility/PHPCompatibility?branch=develop)

[![Minimum PHP Version](https://camo.githubusercontent.com/908d626b9ce3be8d9a2deb7cd964e738e89eefebf956be3589f4405e90c6b36f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706870636f6d7061746962696c6974792f7068702d636f6d7061746962696c6974792e7376673f6d61784167653d33363030)](https://packagist.org/packages/phpcompatibility/php-compatibility)[![Tested on PHP 7.2 to nightly](https://camo.githubusercontent.com/cf4217787dfb1999f175b02df9b51837150e3ed4fc9ff4bb4476b8a9e2f8d6dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7465737465642532306f6e2d504850253230372e32253230253743253230372e33253230253743253230372e34253230253743253230382e30253230253743253230382e31253230253743253230382e32253230253743253230382e33253230253743253230382e34253230253743253230382e352532302537432532306e696768746c792532302d627269676874677265656e2e7376673f6d61784167653d32343139323030)](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/test.yml)

This is a set of sniffs for [PHP\_CodeSniffer](https://github.com/PHPCSStandards/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.

- [PHP Version Support](#php-version-support)
- [Funding](#funding)
- [Requirements](#requirements)
- [Installation](#installation)
    - [Composer Project-based Installation](#composer-project-based-installation)
    - [Composer Global Installation](#composer-global-installation)
    - [Updating your PHPCompatibility install to a newer version](#updating-your-phpcompatibility-install-to-a-newer-version)
    - [Using your PHPCompatibility install](#using-your-phpcompatibility-install)
- [Sniffing your code for compatibility with specific PHP version(s)](#sniffing-your-code-for-compatibility-with-specific-php-versions)
    - [Using a framework/CMS/polyfill specific ruleset](#using-a-frameworkcmspolyfill-specific-ruleset)
- [Using a custom ruleset](#using-a-custom-ruleset)
    - [`testVersion` in the ruleset versus command-line](#testversion-in-the-ruleset-versus-command-line)
    - [PHPCompatibility specific options](#phpcompatibility-specific-options)
- [Projects extending PHPCompatibility](#projects-extending-phpcompatibility)
- [Contributing](#contributing)
- [License](#license)

PHP Version Support
-------------------

[](#php-version-support)

The project aims to cover all PHP compatibility changes introduced since PHP 5.0 up to the latest PHP release. This is an ongoing process and coverage is not yet 100% (if, indeed, it ever could be). Progress is tracked on [our GitHub issue tracker](https://github.com/PHPCompatibility/PHPCompatibility/issues).

Pull requests that check for compatibility issues in PHP 4 code - in particular between PHP 4 and PHP 5.0 - are welcome as there are still situations where people need help upgrading legacy systems. However, coverage for changes introduced before PHP 5.1 will remain patchy as sniffs for this are not actively being developed at this time.

Funding
-------

[](#funding)

**This project needs funding.**

The project team has spend thousands of hours creating and maintaining this package. This is unsustainable without funding.

If you use PHPCompatibility, please fund this work by donating to the [PHP\_CodeSniffer Open Collective](https://opencollective.com/php_codesniffer).

Requirements
------------

[](#requirements)

- PHP 7.2+
- PHP\_CodeSniffer: 4.0.1+.
- PHPCSUtils: 1.1.2+

The sniffs are designed to give the same results regardless of which PHP version you are using to run PHP\_CodeSniffer. You should get consistent results independently of the PHP version used in your test environment, though for the best results it is recommended to run the sniffs on a recent PHP version in combination with a recent PHP\_CodeSniffer version.

As of version 8.0.0, the PHPCompatibility standard can also be used with PHP\_CodeSniffer 3.x.
As of version 9.0.0, support for PHP\_CodeSniffer 1.5.x and low 2.x versions &lt; 2.3.0 has been dropped.
As of version 10.0.0, support for PHP &lt; 7.2 and PHP\_CodeSniffer &lt; 4.0.1 has been dropped (and support for PHP\_CodeSniffer 4.x was added).

Installation
------------

[](#installation)

As of PHPCompatibility 10.0.0, installation via [Composer](https://getcomposer.org/) using the below instructions is the only supported type of installation.

Composer will automatically install the project dependencies and register the PHPCompatibility ruleset with PHP\_CodeSniffer using the [Composer PHPCS plugin](https://github.com/PHPCSStandards/composer-installer).

> If you are upgrading from an older PHPCompatibility version to version 10.0.0, please read the [Upgrade guide](https://github.com/PHPCompatibility/PHPCompatibility/wiki/Upgrading-to-PHPCompatibility-10.0) first!

### Composer Project-based Installation

[](#composer-project-based-installation)

Run the following from the root of your project:

```
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev phpcompatibility/php-compatibility:"^10.0.0@dev"
```

### Composer Global Installation

[](#composer-global-installation)

Alternatively, you may want to install this standard globally:

```
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev phpcompatibility/php-compatibility:"^10.0.0@dev"
```

### Updating your PHPCompatibility install to a newer version

[](#updating-your-phpcompatibility-install-to-a-newer-version)

If you installed PHPCompatibility using either of the above commands, you can upgrade to a newer version as follows:

```
# Project local install
composer update phpcompatibility/php-compatibility --with-dependencies

# Global install
composer global update phpcompatibility/php-compatibility --with-dependencies
```

### Using your PHPCompatibility install

[](#using-your-phpcompatibility-install)

You can verify that the PHPCompatibility standard is registered correctly by running `vendor/bin/phpcs -i` on the command line. PHPCompatibility and PHPCSUtils should both be listed as available standards.

Once you have installed PHPCompatibility using either of the above commands, use it as follows:

```
# Project local install
vendor/bin/phpcs -ps . --standard=PHPCompatibility

# Global install
%USER_DIRECTORY%/Composer/vendor/bin/phpcs -ps . --standard=PHPCompatibility
```

> **Pro-tip**: For the convenience of using `phpcs` as a global command, use the *Global install* method and add the path to the `%USER_DIRECTORY%/Composer/vendor/bin` directory to the `PATH` environment variable for your operating system.

Sniffing your code for compatibility with specific PHP version(s)
-----------------------------------------------------------------

[](#sniffing-your-code-for-compatibility-with-specific-php-versions)

- Run the coding standard from the command-line with `phpcs -p . --standard=PHPCompatibility`.
- By default, you will only receive notifications about deprecated and/or removed PHP features.
- To get the most out of the PHPCompatibility standard, you should specify a `testVersion` to check against. That will enable the checks for both deprecated/removed PHP features as well as the detection of code using new PHP features.
    - You can run the checks for just one specific PHP version by adding `--runtime-set testVersion 5.5` to your command line command.
    - You can also specify a range of PHP versions that your code needs to support. In this situation, compatibility issues that affect any of the PHP versions in that range will be reported: `--runtime-set testVersion 5.3-5.5`.
    - As of PHPCompatibility 7.1.3, you can omit one part of the range if you want to support everything above or below a particular version, i.e. use `--runtime-set testVersion 7.0-` to run all the checks for PHP 7.0 and above.
- By default the report will be sent to the console, if you want to save the report to a file, add the following to the command line command: `--report-full=path/to/report-file`. For more information and other reporting options, check the [PHP\_CodeSniffer wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting).

### Using a framework/CMS/polyfill specific ruleset

[](#using-a-frameworkcmspolyfill-specific-ruleset)

As of mid 2018, a limited set of framework/CMS specific rulesets is available. These rulesets are hosted in their own repositories.

- `PHPCompatibilityJoomla` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityJoomla) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-joomla)
- `PHPCompatibilityWP` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityWP) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)

Since the autumn of 2018, there are also a number of PHP polyfill specific rulesets available:

- `PHPCompatibilityPasswordCompat` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityPasswordCompat) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-passwordcompat): accounts for @ircmaxell's [`password_compat`](https://github.com/ircmaxell/password_compat) polyfill library.
- `PHPCompatibilityParagonie` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityParagonie) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-paragonie): contains two rulesets which account for the Paragonie [`random_compat`](https://github.com/paragonie/random_compat) and [`sodium_compat`](https://github.com/paragonie/sodium_compat) polyfill libraries respectively.
- `PHPCompatibilitySymfony` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilitySymfony) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-symfony): contains a number of rulesets which account for various PHP polyfill libraries offered by the Symfony project. For more details about the available rulesets, please check out the [README of the PHPCompatibilitySymfony](https://github.com/PHPCompatibility/PHPCompatibilitySymfony/blob/master/README.md) repository.

If you want to make sure you have all PHPCompatibility rulesets available at any time, you can use the `PHPCompatibilityAll` package [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityAll) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-all).

**IMPORTANT:** Framework/CMS/Polyfill specific rulesets do not set the minimum PHP version for your project, so you will still need to pass a `testVersion` to get the most accurate results.

Using a custom ruleset
----------------------

[](#using-a-custom-ruleset)

Like with any PHP\_CodeSniffer standard, you can add PHPCompatibility to a custom PHP\_CodeSniffer ruleset.

```

    My rules for PHP_CodeSniffer

```

You can also set the `testVersion` from within the ruleset:

```

```

Other advanced options, such as changing the message type or severity of select sniffs, as described in the [PHPCS Annotated ruleset](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.

### `testVersion` in the ruleset versus command-line

[](#testversion-in-the-ruleset-versus-command-line)

Starting with PHP\_CodeSniffer 3.3.0, a `testVersion` set via the command-line will overrule the `testVersion` in the ruleset.

This allows for more flexibility when, for instance, your project needs to comply with PHP `5.5-`, but you have a bootstrap file which needs to be compatible with PHP `5.2-`.

Additionally, as of PHP\_CodeSniffer 4.0.0, a `testVersion` set in an included ruleset can now be overruled from your project (root) ruleset.

### PHPCompatibility specific options

[](#phpcompatibility-specific-options)

At this moment, there are two sniffs which have a property which can be set via the ruleset. More custom properties may become available in the future.

The `PHPCompatibility.Extensions.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions. This might clash with userland functions using the same function prefix.

To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.

```

```

The `PHPCompatibility.Interfaces.RemovedSerializable` sniff needs to know about all interfaces which extend the `Serializable` interface to provide the most reliable results. The sniff will warn when it encounters an interface extending the `Serializable` interface which is unknown to the sniff and recommend for the interface name to be added to the property.

To inform the sniff about additional interfaces providing the Serializable interface, add a snippet along the lines of the below to your custom ruleset:

```

```

Projects extending PHPCompatibility
-----------------------------------

[](#projects-extending-phpcompatibility)

There are hundreds of public projects using PHPCompatibility or extending on top of it. A short list of some that you might know or have a look at :

- [adamculp/php-code-quality](https://github.com/adamculp/php-code-quality) - a Docker image doing a lot of code quality checks
- PHPCompatibility Checker WordPress plugin : [Wordpress site](https://wordpress.org/plugins/php-compatibility-checker/) and [Github](https://github.com/wpengine/phpcompat/)
- [WordPress Tide project](https://wptide.org/)
- [PHPStorm has built-in support for PHPCompatibility](https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html#788c81b6)
- [Moodle codechecker](https://github.com/moodlehq/moodle-local_codechecker) - A [plugin](https://moodle.org/plugins/local_codechecker) for Moodle [coding style](https://docs.moodle.org/dev/Coding_style), including PHPCompatibility.
- [Github Action](https://github.com/marketplace/actions/php-compatibility) - A Github Action that runs this PHPCS standard on your source code.

Contributing
------------

[](#contributing)

Contributions are very welcome. Please read the [CONTRIBUTING](.github/CONTRIBUTING.md) documentation to get started.

License
-------

[](#license)

This code is released under the GNU Lesser General Public License (LGPL). For more information, visit

###  Health Score

69

—

FairBetter than 100% of packages

Maintenance59

Moderate activity, may be stable

Popularity79

Solid adoption and visibility

Community61

Healthy contributor diversity

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 60.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~133 days

Recently: every ~552 days

Total

33

Last Release

171d ago

Major Versions

5.6 → 7.02016-07-01

7.1.5 → 8.0.02017-08-02

8.2.0 → 9.0.02018-10-07

9.3.5 → 10.0.0-alpha12025-10-20

PHP version history (3 changes)5.5PHP &gt;=5.1.2

8.0.0PHP &gt;=5.3

10.0.0-alpha1PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c276f443673da81d365a16828d46818ea4e3136f7ce05491abcc70f43c82fa4c?d=identicon)[jrfnl](/maintainers/jrfnl)

![](https://www.gravatar.com/avatar/c1ef3caa2b7d98cb0f2d9bee0e50c47d9a4613ccbb7b8b618b070384e0585604?d=identicon)[wimg](/maintainers/wimg)

---

Top Contributors

[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (2727 commits)")[![wimg](https://avatars.githubusercontent.com/u/313511?v=4)](https://github.com/wimg "wimg (1615 commits)")[![MarkMaldaba](https://avatars.githubusercontent.com/u/1492120?v=4)](https://github.com/MarkMaldaba "MarkMaldaba (31 commits)")[![sumpygump](https://avatars.githubusercontent.com/u/676007?v=4)](https://github.com/sumpygump "sumpygump (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![afilina](https://avatars.githubusercontent.com/u/199835?v=4)](https://github.com/afilina "afilina (11 commits)")[![cabernet-zerve](https://avatars.githubusercontent.com/u/6884823?v=4)](https://github.com/cabernet-zerve "cabernet-zerve (11 commits)")[![okkun-sh](https://avatars.githubusercontent.com/u/29437562?v=4)](https://github.com/okkun-sh "okkun-sh (7 commits)")[![Nikschavan](https://avatars.githubusercontent.com/u/2931091?v=4)](https://github.com/Nikschavan "Nikschavan (7 commits)")[![fredden](https://avatars.githubusercontent.com/u/334786?v=4)](https://github.com/fredden "fredden (5 commits)")[![ehpc](https://avatars.githubusercontent.com/u/324517?v=4)](https://github.com/ehpc "ehpc (4 commits)")[![octalmage](https://avatars.githubusercontent.com/u/142006?v=4)](https://github.com/octalmage "octalmage (4 commits)")[![jrchamp](https://avatars.githubusercontent.com/u/625298?v=4)](https://github.com/jrchamp "jrchamp (3 commits)")[![stevegrunwell](https://avatars.githubusercontent.com/u/233836?v=4)](https://github.com/stevegrunwell "stevegrunwell (3 commits)")[![GaryJones](https://avatars.githubusercontent.com/u/88371?v=4)](https://github.com/GaryJones "GaryJones (2 commits)")[![gena01](https://avatars.githubusercontent.com/u/312125?v=4)](https://github.com/gena01 "gena01 (2 commits)")[![kakakakakku](https://avatars.githubusercontent.com/u/1573290?v=4)](https://github.com/kakakakakku "kakakakakku (2 commits)")[![kenguest](https://avatars.githubusercontent.com/u/234118?v=4)](https://github.com/kenguest "kenguest (2 commits)")[![magikstm](https://avatars.githubusercontent.com/u/24783458?v=4)](https://github.com/magikstm "magikstm (2 commits)")[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (2 commits)")

---

Tags

compatibilitycompatibility-testingcomposercustom-rulesetphpphp-codesnifferphp-featuresphp-versionsphpcompatibilityphpcompatibility-standardphpcsrulesetcompatibilitystandardsphpcs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpcompatibility-php-compatibility/health.svg)

```
[![Health](https://phpackages.com/badges/phpcompatibility-php-compatibility/health.svg)](https://phpackages.com/packages/phpcompatibility-php-compatibility)
```

###  Alternatives

[automattic/vipwpcs

PHP\_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions

25510.2M145](/packages/automattic-vipwpcs)[wptrt/wpthemereview

PHP\_CodeSniffer rules (sniffs) to verify theme compliance with the rules for theme hosting on wordpress.org

217736.5k29](/packages/wptrt-wpthemereview)[yoast/yoastcs

PHP\_CodeSniffer rules for Yoast projects

221.1M29](/packages/yoast-yoastcs)[mayflower/mo4-coding-standard

PHP CodeSniffer ruleset implementing the MO4 coding standards extending the Symfony coding standards.

17508.3k5](/packages/mayflower-mo4-coding-standard)[phpcompatibility/phpcompatibility-all

A set of rulesets for PHP\_CodeSniffer to check for PHP cross-version compatibility issues and opportunities to modernize code in PHP projects.

1361.7k](/packages/phpcompatibility-phpcompatibility-all)[orisai/coding-standard

Strict PHP coding standard

19193.5k62](/packages/orisai-coding-standard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
