WordPress and PHP 7.3

PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher 7.3 is in the final stages of its release cycle. As of the publish date of this post, version 7.3.0RC3 has been released and the final release of PHP 7.3.0 is scheduled for December 13th.

As the changes in PHP 7.3 were solidified earlier this year, contributors to WordPress CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. worked to identify compatibility issues within the codebase. Overall, the changes needed to declare full PHP 7.3 support are minor, and are all being made.

WordPress aims to fully support PHP 7.3 in its next release.

Here is a breakdown of the changes in PHP 7.3 that pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party and theme developers need to be aware of and should accommodate in their code.

New Function: is_countable()

It is considered good practice to validate variables before using them. Parameters passed to functions may not be of the variable type expected. Similarly, the type of variable returned by a filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. may have changed due to incorrect usage of the filter by plugins or themes.

In PHP 7.2, a warning was introduced when count() is used on an uncountable value. PHP 7.3 introduces the is_countable() function to help detect if a variable is in fact countable. This, paired with is_iterable() (introduced in PHP 7.1) allows developers to better follow this best practice.

In WordPress 4.9.6, two polyfill functions were introduced to help developers follow this best practice regardless of the PHP version a site is running. Using these functions in your code will ensure warnings are not triggered when sites are upgraded to newer versions of PHP.

Undefined Variables and compact()

compact() is a function in PHP that creates an array of values from a list of variable names. If an undefined variable is specified, the resulting array will not contain an index for that variable. This could cause some unexpected behavior due to missing indexes and some scenarios that are difficult to debug.

Starting in PHP 7.3, a notice will be triggered when an undefined variable is passed to compact() to help with identify such situations.

switch() and continue

In PHP, applying continue to a switch() statement causes the same behavior as break. However, in other languages, using continue within switch() statements will continue the surrounding loopLoop The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post. https://codex.wordpress.org/The_Loop. instead (the equivalent of continue 2).

Starting in PHP 7.3, a warning will be generated when using continue to target a switch() control structure (break should always be used instead). The two instances of this pattern in WordPress Core have been corrected.

while ($foo) {
    switch ($foo) {
        case "bar":
            continue; // This now throws a warning.
            break;    // Use this for equivalent behavior.
            continue 2; // No warning, correctly targets the while loop.
    }
}

Summary

As always, reading through the complete upgrade document is highly recommended.

Even as WordPress Core continues to expand its support for new versions of PHP, there is no intention of abandoning support for older versions until usage numbers show that the impact on users will be minimal. If you wish to help with this, an effort to decrease the usage numbers for older versions of PHP is being lead by the #core-php team through the servehappy initiative.

WordPress continues to encourage all users to run the latest and greatest versions of PHP, including PHP7.3 upon its official release.

A full list of tickets related to PHP 7.3 support can be found on Trac.