{"id":14985382,"url":"https://github.com/phpcompatibility/phpcompatibility","last_synced_at":"2026-04-02T01:36:58.386Z","repository":{"id":2628218,"uuid":"3614664","full_name":"PHPCompatibility/PHPCompatibility","owner":"PHPCompatibility","description":"PHP Compatibility check for PHP_CodeSniffer","archived":false,"fork":false,"pushed_at":"2025-03-03T02:31:19.000Z","size":10123,"stargazers_count":2233,"open_issues_count":81,"forks_count":199,"subscribers_count":56,"default_branch":"develop","last_synced_at":"2025-05-03T07:56:09.489Z","etag":null,"topics":["compatibility","compatibility-testing","composer","custom-ruleset","php","php-codesniffer","php-features","php-versions","phpcompatibility","phpcompatibility-standard","phpcs","ruleset"],"latest_commit_sha":null,"homepage":"http://techblog.wimgodden.be/tag/codesniffer/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PHPCompatibility.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"php_codesniffer","github":["PHPCompatibility","jrfnl"],"thanks_dev":"u/gh/phpcompatibility"}},"created_at":"2012-03-03T23:36:15.000Z","updated_at":"2025-05-02T14:23:32.000Z","dependencies_parsed_at":"2023-11-13T02:29:57.460Z","dependency_job_id":"5f150b08-a0e2-40a0-8e4e-933dd3cde971","html_url":"https://github.com/PHPCompatibility/PHPCompatibility","commit_stats":{"total_commits":2463,"total_committers":58,"mean_commits":42.46551724137931,"dds":"0.26512383272431994","last_synced_commit":"3f79f96be9289a49eb85a4db3e8f5b7d55ba06d2"},"previous_names":["wimg/phpcompatibility"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPCompatibility%2FPHPCompatibility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPCompatibility%2FPHPCompatibility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPCompatibility%2FPHPCompatibility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPCompatibility%2FPHPCompatibility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHPCompatibility","download_url":"https://codeload.github.com/PHPCompatibility/PHPCompatibility/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252773066,"owners_count":21802042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compatibility","compatibility-testing","composer","custom-ruleset","php","php-codesniffer","php-features","php-versions","phpcompatibility","phpcompatibility-standard","phpcs","ruleset"],"created_at":"2024-09-24T14:10:50.214Z","updated_at":"2026-04-02T01:36:58.379Z","avatar_url":"https://github.com/PHPCompatibility.png","language":"PHP","readme":"# PHP Compatibility Coding Standard for PHP_CodeSniffer\n\n\u003cdiv aria-hidden=\"true\"\u003e\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/phpcompatibility/php-compatibility?label=stable)](https://packagist.org/packages/phpcompatibility/php-compatibility)\n[![Latest Unstable Version](https://img.shields.io/badge/unstable-dev--develop-e68718.svg?maxAge=2419200)](https://packagist.org/packages/phpcompatibility/php-compatibility#dev-develop)\n![Awesome](https://img.shields.io/badge/awesome%3F-yes!-brightgreen.svg)\n[![License](https://img.shields.io/github/license/PHPCompatibility/PHPCompatibility?color=00a7a7)](https://github.com/PHPCompatibility/PHPCompatibility/blob/master/LICENSE)\n\n[![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)\n[![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)\n[![Coverage Status](https://coveralls.io/repos/github/PHPCompatibility/PHPCompatibility/badge.svg?branch=develop)](https://coveralls.io/github/PHPCompatibility/PHPCompatibility?branch=develop)\n\n[![Minimum PHP Version](https://img.shields.io/packagist/php-v/phpcompatibility/php-compatibility.svg?maxAge=3600)](https://packagist.org/packages/phpcompatibility/php-compatibility)\n[![Tested on PHP 7.2 to nightly](https://img.shields.io/badge/tested%20on-PHP%207.2%20|%207.3%20|%207.4%20|%208.0%20|%208.1%20|%208.2%20|%208.3%20|%208.4%20|%208.5%20|%20nightly%20-brightgreen.svg?maxAge=2419200)](https://github.com/PHPCompatibility/PHPCompatibility/actions/workflows/test.yml)\n\n\u003c/div\u003e\n\nThis is a set of sniffs for [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) that checks for PHP cross-version compatibility.\nIt will allow you to analyse your code for compatibility with higher and lower versions of PHP.\n\n* [PHP Version Support](#php-version-support)\n* [Funding](#funding)\n* [Requirements](#requirements)\n* [Installation](#installation)\n    - [Composer Project-based Installation](#composer-project-based-installation)\n    - [Composer Global Installation](#composer-global-installation)\n    - [Updating your PHPCompatibility install to a newer version](#updating-your-phpcompatibility-install-to-a-newer-version)\n    - [Using your PHPCompatibility install](#using-your-phpcompatibility-install)\n* [Sniffing your code for compatibility with specific PHP version(s)](#sniffing-your-code-for-compatibility-with-specific-php-versions)\n    - [Using a framework/CMS/polyfill specific ruleset](#using-a-frameworkcmspolyfill-specific-ruleset)\n* [Using a custom ruleset](#using-a-custom-ruleset)\n    - [`testVersion` in the ruleset versus command-line](#testversion-in-the-ruleset-versus-command-line)\n    - [PHPCompatibility specific options](#phpcompatibility-specific-options)\n* [Projects extending PHPCompatibility](#projects-extending-phpcompatibility)\n* [Contributing](#contributing)\n* [License](#license)\n\n## PHP Version Support\n\nThe 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).\n\nPull 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.\n\n\n## Funding\n\n**This project needs funding.**\n\nThe project team has spend thousands of hours creating and maintaining this package. This is unsustainable without funding.\n\nIf you use PHPCompatibility, please fund this work by donating to the [PHP_CodeSniffer Open Collective](https://opencollective.com/php_codesniffer).\n\n\n## Requirements\n\n* PHP 7.2+\n* PHP_CodeSniffer: 4.0.1+.\n* PHPCSUtils: 1.1.2+\n\nThe 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.\n\nAs of version 8.0.0, the PHPCompatibility standard can also be used with PHP_CodeSniffer 3.x.  \nAs of version 9.0.0, support for PHP_CodeSniffer 1.5.x and low 2.x versions \u003c 2.3.0 has been dropped.  \nAs of version 10.0.0, support for PHP \u003c 7.2 and PHP_CodeSniffer \u003c 4.0.1 has been dropped (and support for PHP_CodeSniffer 4.x was added).\n\n\n## Installation\n\nAs of PHPCompatibility 10.0.0, installation via [Composer](https://getcomposer.org/) using the below instructions is the only supported type of installation.\n\nComposer 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).\n\n\u003e 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!\n\n### Composer Project-based Installation\n\nRun the following from the root of your project:\n```bash\ncomposer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true\ncomposer require --dev phpcompatibility/php-compatibility:\"^10.0.0@dev\"\n```\n\n### Composer Global Installation\n\nAlternatively, you may want to install this standard globally:\n```bash\ncomposer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true\ncomposer global require --dev phpcompatibility/php-compatibility:\"^10.0.0@dev\"\n```\n\n### Updating your PHPCompatibility install to a newer version\n\nIf you installed PHPCompatibility using either of the above commands, you can upgrade to a newer version as follows:\n```bash\n# Project local install\ncomposer update phpcompatibility/php-compatibility --with-dependencies\n\n# Global install\ncomposer global update phpcompatibility/php-compatibility --with-dependencies\n```\n\n### Using your PHPCompatibility install\n\nYou can verify that the PHPCompatibility standard is registered correctly by running `vendor/bin/phpcs -i` on the command line.\nPHPCompatibility and PHPCSUtils should both be listed as available standards.\n\nOnce you have installed PHPCompatibility using either of the above commands, use it as follows:\n```bash\n# Project local install\nvendor/bin/phpcs -ps . --standard=PHPCompatibility\n\n# Global install\n%USER_DIRECTORY%/Composer/vendor/bin/phpcs -ps . --standard=PHPCompatibility\n```\n\n\u003e **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.\n\n\n## Sniffing your code for compatibility with specific PHP version(s)\n\n* Run the coding standard from the command-line with `phpcs -p . --standard=PHPCompatibility`.\n* By default, you will only receive notifications about deprecated and/or removed PHP features.\n* 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.\n    - You can run the checks for just one specific PHP version by adding `--runtime-set testVersion 5.5` to your command line command.\n    - 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`.\n    - 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.\n* 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`.\n    For more information and other reporting options, check the [PHP_CodeSniffer wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting).\n\n\n### Using a framework/CMS/polyfill specific ruleset\n\nAs of mid 2018, a limited set of framework/CMS specific rulesets is available. These rulesets are hosted in their own repositories.\n* `PHPCompatibilityJoomla` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityJoomla) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-joomla)\n* `PHPCompatibilityWP` [GitHub](https://github.com/PHPCompatibility/PHPCompatibilityWP) | [Packagist](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)\n\nSince the autumn of 2018, there are also a number of PHP polyfill specific rulesets available:\n* `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.\n* `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.\n* `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.\n\nIf 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).\n\n**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.\n\n\n## Using a custom ruleset\n\nLike with any PHP_CodeSniffer standard, you can add PHPCompatibility to a custom PHP_CodeSniffer ruleset.\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cruleset name=\"Custom ruleset\"\u003e\n    \u003cdescription\u003eMy rules for PHP_CodeSniffer\u003c/description\u003e\n\n    \u003c!-- Run against the PHPCompatibility ruleset --\u003e\n    \u003crule ref=\"PHPCompatibility\"/\u003e\n\n    \u003c!-- Run against a second ruleset --\u003e\n    \u003crule ref=\"PSR2\"/\u003e\n\n\u003c/ruleset\u003e\n```\n\nYou can also set the `testVersion` from within the ruleset:\n```xml\n    \u003c!-- Check for cross-version support for PHP 7.2 and higher. --\u003e\n    \u003cconfig name=\"testVersion\" value=\"7.2-\"/\u003e\n```\n\nOther 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.\n\n### `testVersion` in the ruleset versus command-line\n\nStarting with PHP_CodeSniffer 3.3.0, a `testVersion` set via the command-line will overrule the `testVersion` in the ruleset.\n\nThis 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-`.\n\nAdditionally, as of PHP_CodeSniffer 4.0.0, a `testVersion` set in an included ruleset can now be overruled from your project (root) ruleset.\n\n\n### PHPCompatibility specific options\n\nAt 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.\n\nThe `PHPCompatibility.Extensions.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions.\nThis might clash with userland functions using the same function prefix.\n\nTo whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.\n```xml\n    \u003c!-- Whitelist the mysql_to_rfc3339() and mysql_another_function() functions. --\u003e\n    \u003crule ref=\"PHPCompatibility.Extensions.RemovedExtensions\"\u003e\n        \u003cproperties\u003e\n            \u003cproperty name=\"functionWhitelist\" type=\"array\"\u003e\n                \u003celement value=\"mysql_to_rfc3339\"/\u003e\n                \u003celement value=\"mysql_another_function\"/\u003e\n            \u003c/property\u003e\n        \u003c/properties\u003e\n    \u003c/rule\u003e\n```\n\nThe `PHPCompatibility.Interfaces.RemovedSerializable` sniff needs to know about all interfaces which extend the `Serializable` interface to provide the most reliable results.\nThe 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.\n\nTo inform the sniff about additional interfaces providing the Serializable interface, add a snippet along the lines of the below to your custom ruleset:\n```xml\n    \u003crule ref=\"PHPCompatibility.Interfaces.RemovedSerializable\"\u003e\n        \u003cproperties\u003e\n            \u003cproperty name=\"serializableInterfaces\" type=\"array\"\u003e\n                \u003celement value=\"MyCustomSerializableInterface\"/\u003e\n                \u003celement value=\"AnotherSerializableInterface\"/\u003e\n            \u003c/property\u003e\n        \u003c/properties\u003e\n    \u003c/rule\u003e\n```\n\n## Projects extending PHPCompatibility\n\nThere 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 :\n* [adamculp/php-code-quality](https://github.com/adamculp/php-code-quality) - a Docker image doing a lot of code quality checks\n* PHPCompatibility Checker WordPress plugin : [Wordpress site](https://wordpress.org/plugins/php-compatibility-checker/) and [Github](https://github.com/wpengine/phpcompat/)\n* [WordPress Tide project](https://wptide.org/)\n* [PHPStorm has built-in support for PHPCompatibility](https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html#788c81b6)\n* [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.\n* [Github Action](https://github.com/marketplace/actions/php-compatibility) - A Github Action that runs this PHPCS standard on your source code.\n\n## Contributing\n\nContributions are very welcome. Please read the [CONTRIBUTING](.github/CONTRIBUTING.md) documentation to get started.\n\n## License\n\nThis code is released under the GNU Lesser General Public License (LGPL). For more information, visit \u003chttp://www.gnu.org/copyleft/lesser.html\u003e\n","funding_links":["https://opencollective.com/php_codesniffer","https://github.com/sponsors/PHPCompatibility","https://github.com/sponsors/jrfnl","https://thanks.dev/u/gh/phpcompatibility"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpcompatibility%2Fphpcompatibility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpcompatibility%2Fphpcompatibility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpcompatibility%2Fphpcompatibility/lists"}