Many technology enthusiasts are enthusiastic about PHP 8.0 due to its substantial changes. It will take time for everyone to grasp WordPress PHP 8 Compatibility, configurations, advantages, and more related to PHP 8. Among these considerations, a significant question arises: “Is WordPress currently compatible with PHP 8? If not, what steps are necessary.

Upon the release of PHP 8, our team of experts immediately delved into comprehensive testing at the deepest levels. The results we’ve obtained are truly astonishing. We are excited to share our findings, reports, and test outcomes confidently.

We will not only outline the changes but also provide unbiased advice on whether updating to PHP 8 is recommended for you.

So many breaking changes in PHP 8: But what’s the reason?

PHP 8 represents a significant PHP update, often involving the removal of negatives in major versions from recent minor version ranges. Notably, PHP 8 has seen a reduction in several breaking changes that were present in the previous 7.* versions.

Therefore, for projects that have been consistently updated throughout the years, addressing any deprecated APIs, the upgrade shouldn’t pose significant challenges. In reality, PHP 7.* versions have experienced a considerably larger number of deprecations compared to earlier PHP versions.

Transitioning from PHP 5.6 to PHP 7 proved relatively straightforward, whereas navigating the shift from 7.x to 8 might pose challenges—particularly for legacy codebases like WordPress and numerous associated plugins.

Certainly, in the case of codebases that are well-typed or kept current with the latest PHP versions, significant issues are less likely to arise. Nevertheless, it’s important to acknowledge that WordPress doesn’t fall under this category of codebase.

Is WordPress already compatible with PHP 8?

Honestly speaking, WordPress may already have compatibility with PHP 8, but we can’t definitively assert that. WordPress aims to maintain compatibility with the latest PHP versions consistently. However, in this guide, we will thoroughly examine the primary concerns.

We have diligently addressed a wide range of compatibility issues using various available strategies. In the following sections, we will explore the details of our efforts, including the identified challenges and the solutions we devised.

What performance changes are coming?

One of the significant and potentially exciting features introduced in PHP 8 is JIT (Just In Time) compilation and debugging. As commonly understood, PHP functions as an interpreted language. In other words, it undergoes translation into machine code during runtime.

JIT monitors frequently utilized code and optimizes the translation of machine code for enhanced reusability. This can lead to significant performance enhancements for specific functionalities.

The integration of Just-In-Time (JIT) compilation into different programming languages, like JavaScript, has historically led to a surge in the development of novel applications. For instance, the idea of virtual machines executing in JS would have been unimaginable during the nascent stages of the web. Several tasks that previously required server-side module installations are now becoming feasible through core PHP libraries.

Currently, web applications such as WordPress experience only marginal performance improvements. Furthermore, a significant amount of time is required before developers or typical WordPress users can fully experience the benefits offered by this new feature.

Numerous additional features aim to enhance developers’ experiences. However, it’s improbable that these enhancements will be immediately adopted within WP themes and plugins. This reluctance stems from the fact that the majority of these updates could potentially disrupt compatibility with earlier versions of PHP, which are still prevalent across numerous WordPress sites.

How to update PHP for your WordPress site?

This guide outlines a convenient method to update PHP to the latest version without causing any disruptions to your WordPress site.

To understand the process, begin by checking your current PHP version. Next, update WordPress to the latest version. Afterward, install the “one.com PHP scanner” plugin and execute a scan to resolve any possible problems. Subsequently, upgrade PHP to its most recent version. Finally, assess the functionality of your site to ensure it operates as intended.

Let’s walk through the entire process.

1: Check your current PHP version

At the outset, it’s essential to determine the current PHP version in use. Retrieve this information from your website’s phpinfo page.

If your website is hosted on cPanel, you can check the PHP version by following the steps outlined in the article on viewing and changing PHP versions in cPanel.

2: Update WordPress to the newest version

To prevent any issues, make sure to update the WordPress core, plugins, and themes to their latest versions. This will help you avoid potential malfunctions.

  1. Log in to your WordPress Admin, then click Dashboard > Updates.
  2. Ensure you have the most recent WordPress version installed and that all themes and plugins are up to date. Proceed to update your WordPress to the latest version promptly.

3: Install the “one.com PHP scanner

  1. In your WordPress Admin, go to one.com > Plugins
  2. Find the one.com PHP scanner and click on “Install now.
  3. Now, click Activate, and proceed to the next step.

4: Run a scan & fix potential issues

  1. On the left menu, click the PHP scanner.
  2. Select PHP version 7.4, choose “All themes and plugins,” and then click Start scan.
  3. Please proceed once the scan has finished.
  4. You can have three results:
    Compatible = It means all is good!

Warning = It suggests that it should function properly but could potentially encounter problems with future PHP versions.

Error = It’s not very satisfactory and is likely to lead to problems after the update.

Resolve issues with themes or plugins displaying errors by either updating them to their most recent versions or replacing them with alternative plugins that offer similar functionality.

Tip: It is advisable to utilize only regularly updated plugins that demonstrate compatibility with the latest WordPress version. Additionally, removing unnecessary plugins can contribute to improved site performance.

5: Update PHP to the 8.0 version

You’re now ready to update PHP. We advise enabling PHP error messages at the same time. If any problems arise with the code, you’ll receive error messages indicating the root cause and its specific location.

  1. In the control panel, return to PHP and database settings.
  2. Scroll down to PHP error messages.
  3. Click Update after setting the error messages to On.
  4. Change the version below this and tap Update.

6: Please verify if your website is functioning as expected

After successfully updating the PHP version, it may take around 20 minutes for the changes to take effect. For websites with high visitor traffic, this duration could potentially extend to several hours. Therefore, we advise closely monitoring your website multiple times within the next 24 hours.

If your website isn’t functioning as anticipated, the primary culprit could be your theme or plugins. To pinpoint the exact cause of problems, you need to identify.

  1. To temporarily switch to the default WordPress theme, “Twenty Seventeen,” we would say, “Twenty Seventeen” is the theme to use.
  2. Choose all currently installed plugins and deactivate them collectively.
  3. Re-enable themes and plugins one by one, while continuously testing your site’s functionality. This method can help identify the source of issues effectively.

Speaking technically, the current nightly version of WordPress exhibits compatibility with the much-discussed PHP 8, akin to the alignment seen in WordPress releases just prior to the emergence of a new PHP version. If you’re looking to Hire WordPress Developers in USA, you can benefit from their expertise in leveraging this compatibility for your projects.

We conducted thorough testing, employed meticulous fixes, and addressed compatibility issues with the same rigor as PHP compatibility adjustments within the WordPress core. However, failure to adhere to this guide could hinder your comprehension of compatibility challenges and limit your ability to fully leverage the advantages of PHP 8.

WordPress PHP8 Compatibility challenges

Here are several approaches you can use to ensure your current codebase aligns with WordPress PHP 8 Compatibility.

  • Utilize static analysis tools like PHPCompatibility for identifying syntactic issues.
  • Implementing Automated Testing for Runtime Problem Detection
  • Manually testing for runtime problems.

Based on the coverage of your test suite and the ratio of syntactic changes to runtime, These strategies effectively address codebase compatibility with a new PHP version (currently discussing PHP 8).

Indeed, PHP 8 and WordPress present a few additional challenges that hinder the seamless implementation of these strategies for ensuring absolute compatibility. Below, we’ll detail the strategies we’ve employed for WordPress, along with the outcomes we’ve experienced.

Static analysis tools

Due to specific changes in PHP 8.0, static analysis has limitations in detecting problems. In cases where static analysis aims to exceed traditional capabilities and intends to track variable and constant values along with runtime types, such scans’ outcomes will likely have false positives.

PHP Compatibility stands as the sole static analysis tool designed for detecting PHP cross-version compatibility issues.

In addition to PHP compatibility, other static analysis tools report on a broader range of issues. Valuing the results for detecting PHP cross-version compatibility related issues that are genuinely accurate requires a significant investment of time and a deep understanding of the tools, particularly in terms of configuring them to minimize unnecessary noise.

At the same time, these tools constantly face instability as they adapt to changes in the PHP version and update the potential scans. Therefore, we can anticipate that these tools will continue to identify even more issues in the future.

So regardless of what has been and can be discovered further at this time, these tools are likely to uncover more issues in the (near) future.

Scanning WordPress PHP 8 Compatibility

PHPCompatibility identifies the issue of “__destruct() not being called after die() in __construct()” but upon deeper analysis, we find that it’s not problematic in this case.

PHPCompatibility flagged an issue in code utilized by the “Plugin/Theme editor.” Analyzing the involved code revealed a fundamental oversight. While in the editor, WordPress aims to perform minimal code analysis, it disregards PHP 5.3+ code.

Considering the relevant changes in PHP 8, addressing this oversight has become more complex to resolve. We conducted scans using PHPCompatibility with the developed version, and as anticipated, the results differed significantly from those obtained with previous PHP updates. The scanner has identified issues that are maintained externally.

Scanning WordPress with Exakat

In the latest public scan conducted on October 16th, utilizing WP trunk, Exakat reports a total of 149,567 issues.

The WordPress PHP 8 Compatibility report displays a total of 93 issues. However, the report is incomplete, as it doesn’t include an analysis of numbers relevant for PHP 8.

We anticipate that these reports will likely contain a significant number of false positives because WordPress doesn’t employ type declarations. Consequently, the types are extrapolated from the identified code and the types indicated in docblocks. Nonetheless, it remains essential to individually review and assess these issues.

Scanning WordPress with PHPStan

PHPStan scans demand a fully customized ruleset to achieve remotely usable outcomes. Nevertheless, even after investing effort into customization, these scans still end up containing a few false positives, rendering the output unusable.

Notes: We don’t criticize the PHPStan tooling, but the significant reason behind this is that WordPress barely employs type declarations. Conversely, PHPStan primarily caters to projects that utilize modern code.

The most basic configuration produces over 20,000 issues during an initial scan. Even when utilizing the extensively tailored ruleset mentioned above, designed to pinpoint PHP 8 related issues, the results show precisely 580 issues at level 5, alongside an extra 2,150 potential issues at level 7. Although these might include a few false positives, they still generate 380 more issues at level 8, with a similar disclaimer.

The team recently opened a Trac ticket to tackle a list of issues stemming from an unknown configuration. However, the focus is entirely on addressing parameter type mismatches (level 5). A draft PR is now accessible to rectify these problems.

It’s currently unclear whether the proposed fixes are justified or if we should consider the identified issues as false positives.

Testing

Static analysis can only reach a certain extent due to the nature of the problematic swaps in PHP8. Reviewing and testing software manually proves to be arduous work, and humans also tend to overlook things when they have much to watch out for.

When end-users conduct testing, it tends to yield relatively useless outcomes, given that they typically focus on testing the “happy paths.” To attain more dependable results, we require extensive exploratory and regression testing.

Prioritize high-quality automated tests and execute them on PHP 8, as this will provide a clear indication of what PHP 8.0 issues to anticipate.

Upon the release of PHP 8, our team of experts immediately delved into exhaustive testing, and the results can shock anyone! We now possess comprehensive knowledge and take pride in showcasing the reports and outcomes of our testing.

Let’s now proceed to executing automated tests on PHP 8.

Running automated tests on PHP 8

PHPUnit 9.3, released in August 2020, became the initial version officially compatible with PHP 8.0. However, running an automated test suite on PHP poses challenges, as the de facto tool for unit testing.

We are aware that WordPress maintains support for at least PHP 5.6. To run tests on PHP 8.0, any test suite associated with WordPress must have complete compatibility with PHPUnit versions 5 through 9. Although there are tools designed to assist with this, adapting a test suite to achieve compatibility still requires effort and time.

Initiating the tests for WordPress Core on PHP8

The tests for WP Core currently pass and run against PHP 8. These tests conduct on PHPUnit 7.5’s composer-installed version. Although PHPUnit 9.3 is the earliest PHPUnit version officially compatible with PHP 8.

The solution to the latest problem involved copying a specific set of files/classes from PHPUnit 9.3 to the WordPress test suite. We excluded the native PHPUnit classes from being generated in the Composer autoload, allowing us to utilize the copied files from PHPUnit 9.3 within the WordPress test suite. Currently, this approach is functional, but it can be deemed as a makeshift solution and might not be viable in the future. Moreover, it could require ongoing maintenance.

To ensure test quality, the initial approach was likely subpar, as most cases employed loose type checking.

Going deeper, the team opened a Trac ticket to address this issue back in 2016. Due to the stricter type adherence in PHP, they have restored this ticket. The team has invested significant effort in mitigating this problem.
As we wrote, we have incorporated approximately 800 instances (consisting of 676 assertEquals() additions and 96 assertNotEquals()). We have also shifted from loose type checking, reducing it from over 8000 instances.

Testing themes and plugins

Only a small percentage of the available plugins, specifically the professionally developed and more popular ones, have automated tests implemented. In general, this situation is worrisome since a typical WordPress site uses around 19 or 20 plugins. Some sites even operate with a higher number of plugins. Automated testing for themes is even rarer in this context.

Facilitating the execution of these test suites on PHP version 8 presents a formidable challenge. Furthermore, gaining insights into the adaptability of plugins and themes to PHP 8 requires attention before any conclusions can be drawn.

Themes and plugins with tests typically feature two primary types of tests, which may or may not be implemented effectively:

Unit tests: Isolated assessments that criticize WordPress, allowing for the examination of the plugin code, often employ well-known frameworks such as BrainMonkey and Mockery.

Integration tests: Integration tests involve the complete loading of WordPress before executing the test suite. This process utilizes the WP core code and seamlessly integrates with the WP test suite.

Integration tests

WordPress has chosen to remain with PHPUnit 7.5. What implications does this decision have?

We will transition to PHPUnit 7.5 for integration tests related to themes and plugins.

Themes and plugins must either replicate the hack in WP core to achieve seamless integration test execution, or they must utilize the files in WP Core. However, they will subsequently need to generate a custom autoloader because they cannot utilize the same Composer autoload generation hack.

Unit tests

Unit tests using Mockery or BrainMonkey require PHPUnit version greater than 8. The Mockery framework that is accessible for PHPUnit 7.x does not align with PHP 8.0 compatibility. Consequently, ensuring compatibility of these test suites becomes necessary across PHPUnit versions 5 to 9. This certainly introduces an additional challenge.

PHPUnit requires different versions to run each test suite when using both sorts of test suites. To complicate this situation, plugins usually maintain a committed composer.lock file. This file ensures that the plugins’ runtime dependencies stay at a specific version. The chosen version is reliable and fully compatible with PHP 5.6.
Sometimes, to ensure this final aspect, developers impose a PHP 5.6 configuration on the platform through the composer.json file. Consequently, this action also results in the version locking of their development dependencies: BrainMonkey, Mockery, and PHPUnit. These dependencies will be constrained to versions compatible with PHP 5.6. Consequently, running tests on PHP 8.0 would certainly be prevented.

PHP 8 compatibility presents challenges on large WordPress sites

By investigating a chain of breaking changes in PHP 8, we could confirm that this version is likely to cause significant disruptions on websites. The reason for the breakage is unclear and, in some cases, errors will occur in one place but will be generated by a theme or plugin elsewhere. This situation would certainly make debugging these issues quite challenging.

How long do developers have to update?

Each version of PHP has a 2-year life cycle during which developers fix bugs. The PHP development team allocated an additional year to address security issues through patching after releasing PHP 7.4 in November 2019 as the concluding version of PHP 7. Consequently, the PHP 7.4 bugs will receive fixes until November 2021, and security problems will undergo patching until November 2022. The “End of Life” for PHP 7.4 is scheduled at that juncture.

So, the hard cutoff date for November 2022 means that all PHP code must be compatible with PHP 8 by this time. Otherwise, there is a risk of being stuck on a potentially vulnerable PHP version.

Conclusion

PHP 8 will introduce numerous breaking changes. Our report outlines a significant number of these changes, which our experts believe will have a more pronounced impact on WordPress as well as the broader WordPress ecosystem. These changes primarily revolve around warnings evolving into problems, and the introduction of several errors that can be challenging to address. It is possible to identify a higher percentage of these changes at runtime.

Addressing all of these compatibility issues presents a substantial task. To achieve this, you must employ a range of strategies, commencing with static analysis and automated testing. This undertaking demands significant time and effort.

You should possess the necessary tools to execute tasks flawlessly. Projects like WordPress, which need to support a range of PHP versions, introduce several additional complexities in managing various versions of the analysis tools, as we discussed earlier.

Certainly, dealing with the vast runtime and syntactic differences between PHP 5 and 8 becomes quite challenging.

Using PHP 8 with WordPress is not necessarily good or bad. The focus here is not on the argument itself, but rather on the conclusion that emerges – using PHP 8 with WordPress becomes quite challenging.

We’ve also addressed the matter of coverage and WordPress’s PHP dependencies for reliable WordPress PHP 8 Compatibility. High test coverage is essential. Moreover, in the case of PHP 8, this becomes even more critical due to the greater number of compatibility issues compared to the norm. Most of these issues can be identified during runtime.