Most likely you need to have different PHP versions installed. Then you can check compatibility of your code with specified PHP version using shell:

find . -name *.php | xargs -n1 /usr/bin/php -l

php -l command runs PHP in syntax check only mode. The command above will check each PHP file in your project againts compatibility with PHP version located at /usr/bin/php.

Answer from ptkoz on Stack Overflow
Top answer
1 of 6
17

Most likely you need to have different PHP versions installed. Then you can check compatibility of your code with specified PHP version using shell:

find . -name *.php | xargs -n1 /usr/bin/php -l

php -l command runs PHP in syntax check only mode. The command above will check each PHP file in your project againts compatibility with PHP version located at /usr/bin/php.

2 of 6
15

Install the PHP version you want to test and run php -l file.php to test if the file passes the lint check. If PHP is unable to parse the file, it will tell you.

In general, you should be aware of which features became available in which version. Disregarding PHP 5.3 with its several patch versions that added significant improves for a moment, this boils down to knowing what features were brought with PHP 5.4, 5.5, 5.6 and 7.0, and explicitly pointing to that version in your composer.json.

As a hint: 5.4 has short array syntax and traits, 5.5 has generators and finally, 5.6 comes with variadic functions and argument unpacking, and 7.0 has scalar type hinting and return types. It helps to use a IDE that knows about these features and warns you if you use something that isn't supported in the version you selected.

PHP comes with a constant PHP_VERSION that contains the current version you are running on, and has a function version_compare() to allow for easy comparing of version notation as in "which one is greater". This would allow to execute different parts of the code depending on the version, allowing to add compatibility layers for some things you need if you run on lower versions, and using the PHP implementation (usually faster) when running on more recent versions.

Apart from this, you will always stumble upon problems with extensions not being installed. This isn't a problem with the PHP version itself. PHP has function_exists() and method_exists() to detect if you can call something before you do (and fail with a fatal error). You can detect this error condition and either have a different solution, or inform the user he has to add something to his PHP installation.

I would recommend using Travis CI for open source projects. Basically you get it for free, and adding different PHP versions is like adding a new line in the travis.yml configuration file. They do offer plans for private repositories as well. Any other CI installation offering you plenty of PHP versions will also work as long as you are running your code on all the PHP versions you intend to support.

Final suggestion: Drop support for PHP 5.3 and 5.4. These versions are out of maintenance (or leaving security-only fix phase in 2 months from now) and shouldn't really be targeted anymore.

🌐
Daniel Opitz
odan.github.io › 2020 › 12 › 22 › php8-compatibility-check.html
PHP 8 Compatibility Check | Daniel Opitz - Blog
December 22, 2020 - "scripts": { "sniffer:php8": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2" }
Discussions

What is a good tool to check codebase compatibility with PHP 8?

Do what our cto did, just put v8 on the server and composer, push and see what smells bad.

What a fun week that was.

More on reddit.com
🌐 r/PHP
22
13
January 10, 2020
PHP 8.1 mass compatibility check for upgrades from PHP 7.4
You can try Rector with SetList set to LevelSetList::UP_TO_PHP_81 and run vendor/bin/rector process --dry-run The output will show any upgrades required Some will be optional, for example, a switch to case upgrade. If you want to proceed with the upgrades remove the --dry run. It's possible to upgrade in stages by Ignoring Rules Or Paths More on reddit.com
🌐 r/PHP
26
61
January 5, 2023
Plugin/Tool to help check PHP compatibility?
I believe you were looking for plugin such as this one: https://wordpress.org/plugins/plugin-compatibility/ More on reddit.com
🌐 r/Wordpress
2
1
January 8, 2024
PHP 8 Compatibility Checker?

There is really no easy way when plugins developers rely on 3rd parties libraries where they don’t have the idea what might broke during production.

Only plugin developers can guarantee it compatibility with PHP 8 with more logic or breaking changes in the future.

More on reddit.com
🌐 r/Wordpress
3
6
September 20, 2019
People also ask

The static analysis is sufficient to upgrading code to new PHP version?
No, you must run your code with the targeted PHP version to run unit tests and all other tests. The manual test is needed to complete the test.
🌐
phptools.online
phptools.online › php-checker
PHP CS, PHP CS Fixer, Phan and Rector Online | Php Tools Online
Why use Coding Styles checker is needed?
The code source style helps you and other developers to read the code most easily. This php code checker and fixer online service is available free of charge.
🌐
phptools.online
phptools.online › php-checker
PHP CS, PHP CS Fixer, Phan and Rector Online | Php Tools Online
What are the tools available to upgrade the code?
This online PHP code analyzer uses "Rector" to change your snippet code. The rules selected are the default rules to upgrade code to the targeted PHP version.
🌐
phptools.online
phptools.online › php-checker
PHP CS, PHP CS Fixer, Phan and Rector Online | Php Tools Online
🌐
GitHub
github.com › PHPCompatibility › PHPCompatibility
GitHub - PHPCompatibility/PHPCompatibility: PHP Compatibility check for PHP_CodeSniffer · GitHub
PHP Compatibility check for PHP_CodeSniffer. Contribute to PHPCompatibility/PHPCompatibility development by creating an account on GitHub.
Starred by 2.3K users
Forked by 205 users
Languages   PHP
🌐
Peterfisher
peterfisher.me.uk › blog › how-to-check-if-your-code-is-compatible-with-php-8
How to check if your code is compatible with PHP 8 | Peter Fisher
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
🌐
Reddit
reddit.com › r/php › what is a good tool to check codebase compatibility with php 8?
r/PHP on Reddit: What is a good tool to check codebase compatibility with PHP 8?
January 10, 2020 -

Hello,

I have legacy-ish codebase (largely updated and working with PHP 7.4) and I would like to check it for compatibility with PHP 8, however I've yet to find a reliable tool for the job. My current search has taken me to:

- phpCompatibility (https://github.com/PHPCompatibility/PHPCompatibility) works with PHPCs, but seems that targeting PHP8 is a mixed bag (judging by issues that mention some check as WIP)

- Phan (https://github.com/phan/phan) seems that it can check for backward compatibility but I've yet to find a way to configure it for forward-compatibility

Next steps:

- Rector

Has anyone used these or something else to prepare for upgrades to PHP 8 as of yet? I'd appreciate any hints.

Thanks!

🌐
LinuxBlog
linuxblog.io › home › php 8 compatibility check and performance tips
PHP 8 Compatibility Check and Performance Tips
November 11, 2024 - There are some tools available that automate the process of checking your scripts for PHP 8 compatibility. Here is a couple that I can recommend. ... PHP Compatibility checker for PHP_CodeSniffer.
Find elsewhere
🌐
Fivefilters
fivefilters.org › home › blog › testing old code for php 8 compatibility
Testing old code for PHP 8 compatibility - FiveFilters.org
September 12, 2023 - This post will show you how to use PHP Compatibility to test your code for compatibility with newer versions of PHP. You can use it to test an entire folder or a specific file.
🌐
Wetopi
wetopi.com › php-8-wordpress-compatibility
PHP 8 WordPress Compatibility Best Practices - Wetopi
December 27, 2024 - If you intend to address a compatibility test of a WordPress site, with all its plugins and themes, in this case, the best PHP 8 compatibility checker you can find is a test environment running with an exact copy of your production WordPress site.
🌐
Phptools
phptools.online › php-checker
PHP CS, PHP CS Fixer, Phan and Rector Online | Php Tools Online
This form help you to analyse your script code for selected coding standard (PSR2, PSR1, PSR12, Zend, Squiz, MySource, ...). Also, you can check your source code compatibility with most recent version of PHP. The check uses the static analysis to perform audits.
🌐
WordPress
wordpress.org › support › plugin › php-compatibility-checker
[PHP Compatibility Checker] Support | WordPress.org
Compatibility Checker says Updraft Plus is incompatible with PHP 8 · Started by: alteditorbl · 1 · 0 · 2 years, 7 months ago · alteditorbl · 404 and “does not exist” on multiple plugins? Started by: Daniel J. Lewis · 2 · 1 · 2 years, 8 months ago ·
🌐
WordPress
learn.wordpress.org › lesson › testing-your-products-for-php-version-compatibility
Testing your products for PHP version compatibility | Learn WordPress
March 17, 2025 - For example, the Migrating from PHP 7.4.x to PHP 8.0.x guide lists the most important changes between PHP 7.4 and PHP 8.0. <?php /** * Plugin Name: WP Learn Compatibility * Description: Learn to test a plugin for PHP Version Compatibility * ...
🌐
Amnuts
blog.amnuts.com › 2023 › 11 › 09 › easily-check-your-code-for-php-8-2-compatibility
Easily check your code for PHP 8.2 compatibility – Andy's blog o' goodness
November 9, 2023 - This uses the excellent PHPCompatibility library and puts it into a docker container. This means that I can then simply build the container (once is enough, but I run the build ever so often to get any additional changes) and run a bash script, and all of the code in a given directory is checked for compatibility; no additional changes needed!
🌐
WordPress.com
wordpress.com › plugins › php-compatibility-checker
PHP Compatibility Checker Plugin — WordPress.com
December 14, 2023 - Use this plugin to check your site for compatibility up to PHP 8.0!
🌐
GitHub
github.com › amnuts › php-compatibility-checker
GitHub - amnuts/php-compatibility-checker: A simple docker container and script to check the compatibility of code with PHP 8.2
A simple docker container and script to check the compatibility of code with PHP 8.2 - amnuts/php-compatibility-checker
Author   amnuts
🌐
Toms Web Stuff
tomswebstuff.com › blog › php-8-drupal-compatibility-testing
PHP 8 Drupal Compatibility testing | Toms Web Stuff
November 13, 2022 - PHPCompatibility you can now start to audit your Drupal project & check it's PHP 8.x compatibility.
🌐
Aureate Labs
aureatelabs.com › aureate labs › how to check your code is compatible with php? - aureate labs
How to check your code is compatible with PHP? - Aureate Labs
November 29, 2025 - You can set it up using the link ... https://github.com/PHPCompatibility/PHPCompatibility · Note: PHPCompatibility with version > 8.0 will only work with PHP version 7.1....
🌐
GitHub
github.com › willtran › magento2-php-8-compatibility-check
GitHub - willtran/magento2-php-8-compatibility-check: Check modules in app/code and vendor for PHP 8 compatibility status - PHP_CodeSniffer & php-compatibility standard
Description: Check all module in an m2 application for PHP8 compatibility Usage: check:all [options] [--] <root-dir> Arguments: root-dir Options: --php-version[=PHP-VERSION] [default: "8.1"] --threads[=THREADS] [default: "4"]
Author   willtran
🌐
Cloudways
cloudways.com › home › php 8.3: how to update the php version of your wordpress site
PHP 8.3 WordPress: How to Update Your PHP Version in 2025
October 23, 2025 - A. A PHP 8 compatibility checker is a plugin that scans your WordPress site’s themes and plugins to detect code that may not work under PHP 8.
🌐
Medium
medium.com › @chirag.dave › dealing-with-php-version-compatibility-issues-in-your-web-app-ec8c7fc45189
Dealing with PHP Version Compatibility Issues in Your Web App | by Chirag Dave | Medium
November 19, 2024 - To upgrade from PHP 7 to PHP 8, follow these steps: Run a PHP Compatibility Checker to identify deprecated features in your code.
🌐
Drupal
drupal.org › project › upgrade_status › issues › 3218290
Use phpstan to test PHP 8 compatibility of PHP code even on PHP 7 [#3218290] | Drupal.org
April 5, 2022 - Problem/Motivation Drupal 10 plans to require PHP 8. Upgrade Status could leverage PHPStan to find PHP 8 compatibility issues. See https://github.com/phpstan/phpstan/releases/tag/0.12.33 Proposed resolution 1. Add syntax to a test module that is compatible with PHP 7 but not compatible with ...