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
🌐
Phptools
phptools.online
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. The exhaustivity is not guarantee without run of code in real condition on the targeted PHP version. 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.
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.

People also ask

What can the WP Engine PHP Compatibility Checker be used for?
The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
🌐
instawp.com
instawp.com › plugin › php-compatibility-checker
Check PHP Version Compatibility for WordPress Websites | PHP ...
Can the plugin detect runtime compatibility issues?
No, the plugin does not execute theme and plugin code, so it cannot detect runtime compatibility issues.
🌐
instawp.com
instawp.com › plugin › php-compatibility-checker
Check PHP Version Compatibility for WordPress Websites | PHP ...
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 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
It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
Starred by 2.3K users
Forked by 206 users
Languages   PHP
🌐
WP Engine
wpengine.com › home › solutions › php compatibility checker by wp engine
PHP Compatibility Checker by WP Engine
August 18, 2020 - The WP Engine PHP Compatibility Checker is a plugin that can be installed on any WordPress site (not just WP Engine sites), and tells you what version of PHP your site is compatible with.
🌐
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 18, 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!

🌐
WordPress.com
wordpress.com › plugins › php-compatibility-checker
PHP Compatibility Checker Plugin — WordPress.com
The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
🌐
InstaWP
instawp.com › plugin › php-compatibility-checker
Check PHP Version Compatibility for WordPress Websites | PHP Compatibility Checker
December 20, 2023 - The WP Engine PHP Compatibility Checker is a WordPress plugin that checks the compatibility of your PHP version with your theme and plugin code. It provides a report of compatibility issues and suggests updates for themes and plugins.
Rating: 2.7 ​ - ​ 130 votes
Find elsewhere
🌐
phpcompat
wpengine.github.io › phpcompat
PHP Compatibility Checker | phpcompat
The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
🌐
GitHub
github.com › sstalle › php7cc
GitHub - sstalle/php7cc: PHP 7 Compatibility Checker
PHP 7 Compatibility Checker. Contribute to sstalle/php7cc development by creating an account on GitHub.
Starred by 1.5K users
Forked by 121 users
Languages   PHP 100.0% | PHP 100.0%
🌐
WordPress
learn.wordpress.org › lesson › testing-your-products-for-php-version-compatibility
Testing your products for PHP version compatibility | Learn WordPress
March 17, 2025 - You will learn why it’s important to test for PHP version compatibility, where to find information about PHP version changes, as well as two methods to test your plugins and themes against newer PHP versions.
🌐
WordPress
wordpress.org › support › plugin › php-compatibility-checker
[PHP Compatibility Checker] Support | WordPress.org
php checker checking css? Started by: Mauro Vicariotto · 1 · 0 · 1 year, 8 months ago · Mauro Vicariotto · Support for PHP 8.1 · Started by: ahillmortons · 2 · 1 · 1 year, 7 months ago · johnwade · The audit requested does not exist. Started by: lukeca · 2 · 1 · 1 year, 10 months ago · ericscoles · PHP Warnings · Started by: Malae · 1 · 1 · 1 year, 8 months ago · Malae · deprecated WPEngine_PHPCompat\PHP_Compatibility_Checker::$page ·
🌐
xneelo
xneelo.co.za › help-centre › website › managing-website › php-compatibility-checker
PHP Compatibility Checker in konsoleH
May 27, 2025 - Select the PHP version you would like to check against and run the check. The Compatibility Scanner will confirm that the website is compatible or not.
🌐
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 - In this article, you will be learning ways in which you can check if your custom Magento code is compatible with PHP version 7.2 or not.
🌐
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.
🌐
Drupal
drupal.org › taxonomy › term › 187137
php compatibility checker | Drupal.org
There is currently no content classified with this term · Drupal is a registered trademark of Dries Buytaert
🌐
Fortrabbit
blog.fortrabbit.com › php-testing
Testing code for PHP 7
September 19, 2018 - It gives you the most comprehensive help in finding deprecated features and syntax in your code. Using PHPCompatibility requires you to first install PHP CodeSniffer globally and then configure PHPCompatibility as the code standard to use.
🌐
Daniel Opitz
odan.github.io › 2020 › 12 › 22 › php8-compatibility-check.html
PHP 8 Compatibility Check | Daniel Opitz - Blog
December 22, 2020 - The PHP Compatibility Coding Standard for PHP CodeSniffer contains a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility.
🌐
Cu
cu.be › a-comprehensive-guide-to-using-phpcompatibility-in-your-project
A Comprehensive Guide to Using PHPCompatibility in Your Project
IntroductionPHPCompatibility is a set of PHP_CodeSniffer rules that checks your code for cross-version compatibility. It can help you ensure your code runs smoothly across various versions of PHP, making it an invaluable tool for any PHP developer.