How to Check Your Website for PHP 7 Compatibility

Hostgator Web Hosting
How to Check Your Website for PHP 7 Compatibility

Even though PHP 7 is the standard, many websites are using PHP 5 to this day. In most cases, this is because these websites aren’t compatible with PHP 7. And for cause: testing an entire website isn’t an easy task. But it’s important to move to PHP 7. As support for the older version fades, new bugs are fixed. New features are added. Security holes are patched.

For example, PHP 7 changes the way it handles errors. It now generates exceptions that could bypass previous error handling mechanisms in PHP 5. These exceptions need to be caught and dealt with accordingly. You can get a complete list of PHP 7 compatibility changes here.

But will your code run properly on PHP 7? While the development team has tried hard to make everything backward compatible, you might be forced to change quite a few things in your code. With a large codebase, checking all this can be daunting. So here are a few tools to help you automate the process. I’m going to list them in order of ease of use.

1. Using the PhpStorm IDE

PhpStorm is an IDE (Integrated Development Environment) that’s specifically built for coding in PHP. It’s not free, however, and individual licenses start from $89 a year. However, if you happen to use it, or are looking to move your development to a new IDE, it’s the simplest way to check for PHP 7 compatibility.

Version 10 of the software includes a simple menu option that immediately highlights incompatible code. Here’s a screenshot from the blog post announcing it:

PHP7-Readiness-Inline-2

If you’re looking for a “one-click” compatibility check, the PhpStorm IDE is your best option.

2. The PHP 7 Migration Assistant Report (MAR)

The second easiest solution is the GitHub project called PHP 7 MAR. It’s a simple PHP project. Once you download it, you can use your own PHP environment to check any file or folder containing PHP. Here’s a sample command for example:

php mar.php -f="/path/to/file/example.php"

For this to work, you need to have a PHP environment already running on your local machine or server. That’s how the “php” command at the beginning has meaning. Out of all the free command line compatibility checkers, I found this one to be the easiest to set up and use without any additional components.

3. PHP 7 Compatibility Checker

If you know how to use “Phar” archives in PHP, then this method is almost as simple as the one above. Download the “.phar” file from the latest version of PHP 7 Compatibility Checker. Then you use the phar file and pass the PHP file or directory you want to check like this:

php "path to phar file" /path/to/my/file.php

Again, note that this requires you to have the PHP environment enabled on your machine – server, or local.

Anyone of these tools should be great for checking whether or not you need to modify your existing code before migrating to PHP 7. If you already have PHP installed on your test environment, then you’re pretty much half way there already. Just download the above PHP projects or “phar” files and you’re good to go!

One Reply to “How to Check Your Website for PHP 7 Compatibility”!

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclosure: We receive a compensation from some of the companies whose products are presented on our website.