Prepare your WordPress plugins and themes for PHP 8 – WP Tavern
On Monday, main WordPress contributor Jonathan Desrosiers posted a detailed post on the Make WordPress Core blog about the upcoming release of PHP 8 and its impact on WordPress.
PHP 8 is coming
Scheduled for release on November 26, 2020, PHP 8 is the next major update to our favorite scripting language. While previous versions of PHP didn’t have too many negative effects on the WordPress ecosystem, this update has a few disruptive changes that could affect backward compatibility. It should also be noted that many features that were deprecated in PHP 7.x will now be removed in PHP 8.
The status of WordPress Core
In his post, Desrosiers highlights the work that has been done to keep the basic software up to date. âWordPress Core aims to be compatible with PHP 8.0 in version 5.6 (currently scheduled for December 8, 2020),â he wrote.
However, that doesn’t mean it’s safe to upgrade to PHP 8 when WordPress 5.6 is released. WordPress is rarely run on its own and usually relies on at least one theme and a collection of plugins to function as a blog or website. As such, he says, âthe state of PHP 8 support within the larger ecosystem (plugins, themes, etc.) is impossible to know. For this reason, WordPress 5.6 should be considered “beta compatible” with PHP 8.“
What this essentially means is that until most of the major themes and plugins are compatible with PHP 8, WordPress cannot be considered fully compatible.
Understand how PHP 8 could affect your plugin or theme
Companies like Yoast have been preparing for this for a while now. At the end of October, Yoast CTO Omar Reiss, along with his fellow contributors Juliette Reinders Folmer, maintainer of WordPress Coding Standards Sniffs for PHPCS, and Yoast DevOps manager Herre Groen, compiled and published a comprehensive WordPress / PHP 8 compatibility report.
While I highly recommend that you take the time to read the entire report, it describes the main reason why upgrading from PHP 8 could have such a drastic effect on large WordPress sites, especially the WordPress ecosystem. plugins and themes.
“However, versions of PHP 7. * experienced a much larger set of deprecations than previous versions of PHP. Where PHP 5.6 to PHP 7 was a relatively straightforward migration, going from 7.x to 8 could be very painful. , especially for very old code bases, like WordPress and most of the plugins available for it. For well-typed code bases or code bases that have stayed up to date with the latest versions of PHP, there is no is no big deal.
As the maintainer of a few plugins, some built on eight-year-old code, it’s worrying that this upgrade could lead to broken sites.
How to prepare
I asked Reiss and Folmer what plugin and theme developers can do to prepare, and they shared some tips.
First of all, developers should inform themselves about the upcoming changes in PHP 8: read the Make post on PHP 8, read the Yoast PHP8 compatibility report, read the âMigrating from PHP 7.4 to PHP 8.0â section of the PHP manual , and potentially dig deeper by reading the UPGRADING doc in the PHP 8 branch and the RFCs for PHP 8.
Some available tools can be used to help find incompatibilities:
- Run PHP lint on PHP 8 on their code, either via the
php -l(making sure to browse all files) or using PHP Parallel Lint.
- Run PHPCompatibility on their code: it should be noted that almost all PHP 8 related sniffs are in PHPCompatibility version 10.0.0, so people should use the
developbranch or via Composer
dev-developfor now, until the release of version 10.0.0.
- Run the unit / integration tests for the plugin or theme on PHP 8 and fix anything that shows up as an error. This often means that the test suite must first be made compatible with PHPUnit 9.3+. The PHPUnit Polyfills package and the WP Test Utils package (both published under the Yoast GitHub organization) can help you. It is also important to note that considerable test coverage is required to make this reliable.
- Run the WordPress unit tests and WordPress e2e tests with your plugin activated and resolve any issues that arise.
- Check if the (strict) code coverage of said tests is high enough and if not add more tests, making sure both happy and unhappy paths are covered.
- If there are no tests, test everything manually, paying particular attention to “bad paths”, and expect to receive bug reports for the foreseeable future. At the same time, it’s probably a good time to consider implementing unit / integration testing for your plugin or theme.
There is still time, but it is running out
As Desrosiers pointed out in the Make article, WordPress only officially aims to be PHP 8 ready when 5.6 releases in early December. Potentially, this means that many WordPress-focused hosting companies will only consider offering upgrades to their customers once the WordPress core is compatible. So, as plugin and theme developers, we have some time to test our products and prepare them, but this window closes quickly.
Lucky for us, the knowledge and the tools to keep up to date are there. We just have to put them into action.