Skip to content
  1. Blog

WordPress PHP 8.1 Support: Not Found

QWp6t QWp6t on

As of 2023-01-03, the latest version of WordPress (6.1.1) still only has “beta support” for PHP 8.0+. PHP 8.1 was released in Nov 2021. 404 days later, full support for PHP 8.1 is still “not found”.

Notices with WP_DEBUG enabled

For developers, this results in a poor experience when WP_DEBUG is enabled or when running some WP-CLI commands. You’ll get spammed with deprecated notices while working on your PHP 8.1+ based WordPress sites. For example:

Notices from WP-CLI

Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in wp-includes/Requests/Cookie/Jar.php on line 63 Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in wp-includes/Requests/Cookie/Jar.php on line 73 Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in wp-includes/Requests/Cookie/Jar.php on line 89 Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in wp-includes/Requests/Cookie/Jar.php on line 111

Dealing with these deprecation notices (or applying hacks to suppress them, see below) is not just an annoyance, it’s a symptom of WordPress prioritizing “site builders” over developers. This shift in focus has led to the perception that WordPress is more similar to Squarespace than to other, more developer-focused application stacks, such as Laravel and Symfony. This has caused a rift with developers and many of them view WordPress as a subpar product that falls short of the standards set by more reputable platforms. 

It’s illustrative to dig into what’s been holding back PHP 8.1 support.

The biggest blocker for WordPress to properly support recent versions of PHP was the update to Requests library to version 2.0.0: https://core.trac.wordpress.org/ticket/54504

#54504 was opened 14 months ago on 2021-11-24, one day before PHP 8.1 was released. As mentioned, PHP 8.1 was released 404 days ago.

In #54504, you’ll find discussions between the authors of the Requests library, Juliette (@jrf) and Alain Schlesser (@schlessera), essentially fighting with the WordPress core team to get this change merged into WordPress.

Shortly after State of the Word, #54504 was finally closed as fixed 13 months after it was opened and is marked to be included in WordPress 6.2.

It’s time for WordPress core to catch up with the rest of the PHP community and provide full support for modern PHP developers, without the need for workarounds or fights.

Workaround

To workaround these notices from WordPress core, you can use a Composer patch in your Composer-based WordPress install. First, add the following dependencies:

$ composer require cweagans/composer-patches
$ composer require rmccue/requests:v1.8.1

After adding these dependencies, update your composer.json file to include the following patch:

"patches": {
  "rmccue/requests": {
    "Remove PHP 8.1 deprecation notices": "https://patch-diff.githubusercontent.com/raw/WordPress/Requests/pull/505.diff"
  }
}

Props to Alexander Goller for writing about this solution.

Note that this is only for WordPress. There’s no way to suppress these warnings for WP-CLI.

Discuss this post on Roots Discourse

About the author

QWp6t

QWp6t is a full-stack web developer who loves modern PHP. He is the creator of Acorn, which allows WordPress developers to use Laravel services within WordPress.

Subscribe for updates

Join over 8,000 subscribers on our newsletter to get the latest Roots updates and tips on building better WordPress sites

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?