Are you using the PHP compatibility checker to determine which plugins to use on your site? What are its limitations? Let’s talk about it.Are you using the PHP compatibility checker to determine which plugins to use on your site? What are its limitations? Let’s talk about it.

PHP 7 is awesome. It’s one of the best things to happen to WordPress in a long time. It’s safer and faster than any previous version of PHP, and when you turn it on, your WordPress site is noticeably faster both frontend and backend.

With that context, I’m a huge fan of PHP 7. I want as many WordPress sites on it as possible. But with such a fundamental change of your server environment, there are necessary precautions you have to take.

Naturally, you’ll need backups and a good way to revert your PHP version if things don’t go well. Some WordPress hosts provide this ability really well. Honestly, if your host doesn’t allow you to safely update to PHP 7 and potentially revert that change if necessary, consider moving hosts.

The other important thing you need to do is make sure that the theme and plugins you use to run your WordPress website are compatible with PHP 7. For that, many users are going to a new plugin by WP Engine called the “PHP Compatibility Checker.”

Caveats and Pitfalls of the PHP Compatibility Checker Plugin

The PHP Compatibility Checker is a plugin you install on your WordPress website. Once activated, it can scan all your plugins and your theme and let you know if there are any functions that are not compatible with your given version of PHP.

This is a great plugin that is very useful for the greater WordPress Community and WordPress users. I like it. It’s helpful.

BUT!

It has a couple major caveats. Consider this quote from their plugin page:

“This plugin does not execute your theme and plugin code, as such this plugin cannot detect runtime compatibility issues.”

This means the PHP Checker does not actually RUN the code. This plugin depends primarily on a library of code called “CodeSniffer.” A lot of WordPress developers use CodeSniffer. It’s a great tool. But all it does is scan your code — similar to the way the Yoast SEO plugin scans the content of your page.

Scanning for obvious things is useful, both for Codesniffer and for Yoast. But that doesn’t mean the results of that scanning is definitive.

Here’s another quote from the plugin page:

“Please note that linting code is not perfect. This plugin cannot detect unused code-paths that might be used for backwards compatibility, and thus might show false positives.”

“Linting” is the technical term for scanning for developers. This quote basically says that when it finds code that isn’t compatible, it can’t tell you why that code is there or what it does or whether it will work at all. That’s not its job. The plugin’s job is to scan your code against a known list of functions that are deprecated for your given version of PHP. Whether that code is wrapped in other code for backward compatibility reasons or not, doesn’t affect the final results.

The PHP Checker Results

When you run the PHP Checker, it’s going to show you a list of items to be wary of. It will reference the file name and line number where it found the incompatible code. Typically, it will either indicate that the offending code has either triggered a “Warning” or an “Error.”

For example, if you run this plugin with our Give plugin active, you’ll see the following results:
_____________________________________________________________________
219 | WARNING | Use of deprecated PHP4 style class constructor is not supported since PHP 7.
1044 | ERROR | Function set_magic_quotes_runtime() is deprecated since PHP 5.3 and removed since PHP 7.0
280 | WARNING | INI directive ‘safe_mode’ is deprecated since PHP 5.3 and removed since PHP 5.4.
44 | WARNING | Method name “Give_Logging::__setup_hooks” is discouraged; PHP has reserved all method names with a double underscore prefix for future use
_____________________________________________________________________

If you’re an average WordPress user who wants to be informed and careful with your website and do everything correctly, you might see those errors and think: “Oh man! I can’t upgrade to PHP 7 because I need Give and Give isn’t PHP 7 Compatible!”

You’d be right to think that if you only used this tool to make your decisions. But in the end, that’s not correct unfortunately.

Instead, Give — like WordPress itself — seeks to be backward compatible to PHP version 5.3. In order to leverage the best parts of PHP 7 but still work perfectly with older versions of PHP, Give has built in these functions as fall-backs.

You see, we develop Give every single day in PHP 7 environments and have been for over a year now. All of our developers are on PHP 7 every single day. We live and breathe PHP 7. We love it and want every user to be running it all the time. We’d NEVER push code that wasn’t compatible with PHP7. Quite the opposite. Occasionally, we accidentally push code that isn’t compatible with PHP 5.4, or 5.3.

Like I said, the PHP Compatibility Checker plugin is really useful and helpful. Nine times out of ten it could highlight a plugin or theme that is just really outdated or unprepared for PHP 7 and it could save you a lot of heartache. But rather than run the scan, then throw your arms in the air and say “I can’t upgrade because of these crappy plugins!” reach out to the plugin authors with the results of your scan and ask them to clarify. Most likely they’ll be more than happy to clarify or jump on the chance to upgrade their plugins to be compatible.

The Only Way to Check for Compatibility

So what is the best way to check for PHP 7 compatibility? There’s only one answer: A test environment. While the PHP Checker plugin can be generally helpful, the only way to know for sure whether your site works on PHP7 is to run it on PHP7.

Some hosts provide one-click PHP version changing, like Siteground, for example. You can create a staging environment of your website, switch it to PHP7, fully test it, then change your live site with confidence. WP Engine — the authors of the PHP Checker plugin — also has a robust staging environment and their support team is very hands-on when it comes to migrating to PHP7.

Another type of test environment is a local environment. We’ve written many times about the advantages of working locally. There are some really great tools out there that will let you test your website on a local PHP 7 environment. Local by Flywheel or Kalabox are both valuable local environment tools which can help you with that.

If you find that your web host cannot or will not upgrade you to PHP 7, then it’s time to look for a new host. If you don’t have the ability to create a staging environment to test your site effectively before upgrading, then it’s time to either find a new host or invest in learning how to work with a local environment. This stuff is vital for a growing and thriving business or nonprofit organization. The last thing you want to do is cripple your website and your ability to take online donations because you didn’t have the hosting tools you needed to upgrade safely.

Upgrade to PHP 7 Today

With that in mind, upgrade to PHP 7. Today! It’s important, helpful, and fast. This might just be the kick-in-the-pants you need to learn a new skill (i.e. staging, or a local environment), or to spend time on your site in a way you never thought of before.

Matt is Head of Support and Community Outreach at WordImpress.com. He's the author of many free WordPress plugins, a popular blogger at his website, an admin of the Advanced WordPress Facebook group, co-organizer of the San Diego WordPress Meetup, and a frequent WordCamp speaker and attender.

Follow Matt:

2 Responses to “The Best Way To Check Your WordPress Site for PHP Compatibility”

  1. Jim Walker

    My experience in having updated many hundreds of sites to PHP 7 has been that there is no rule or place to check compatibility. Sometimes works, sometimes doesn’t.

    I’ve given up taking the time to use the compatibility plugin checker because it’s not terribly accurate or reliable–just too many variables.

    The better web hosts now have a simple one click button where you “click it” and boom you are PHP7.
    Switch back is another single click.

    if you get the dreaded 500 error – well, you know it broke. Next…
    Another day in the life and times of a WordPress designer developer.

    Reply
    • Todd Edelman

      @Matt – comments only work in “Text” mode. Seems to be an issue with “Visual” mode.

      @Jim – I hear what you’re saying. I just updated a dev site. Front-end works fine but cannot access the WP Admin (Error 500). Any suggestions?

      Reply

Leave a Reply