WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 8 weeks ago

#54428 closed defect (bug) (duplicate)

PHP8.1 deprecation warnings

Reported by: michaing Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback php81
Focuses: Cc:

Description

I recently upgraded to PHP8.1 and see some deprecation warnings now. I doesn't cause issues, but you may want to fix this for PHP8.1 release:

PHP message: PHP 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 /var/www/blog/wp-includes/Requests/Cookie/Jar.php on line 63
PHP message: PHP 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 /var/www/blog/wp-includes/Requests/Cookie/Jar.php on line 73
PHP message: PHP 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 /var/www/blog/wp-includes/Requests/Cookie/Jar.php on line 89
PHP message: PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog/wp-includes/Requests/Cookie/Jar.php on line 102
PHP message: PHP 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 /var/www/blog/wp-includes/Requests/Cookie/Jar.php on line 111
PHP message: PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::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 /var/www/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40
PHP message: PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::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 /var/www/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51
PHP message: PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::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 /var/www/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68
PHP message: PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82
PHP message: PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91
PHP message: PHP Deprecated:  http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /var/www/blog/wp-includes/Requests/Transport/cURL.php on line 345
PHP message: PHP Deprecated:  mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/blog/wp-includes/wp-db.php on line 1168

The second is pretty easy to fix: In wp-includes/wp-db.php line 1162 change the condition from:

if ( ! is_scalar( $string ) && ! is_null( $string ) ) {

to

if ( ! is_scalar( $string ) ) {

Ah, and now I see this has been done already for next release: https://github.com/WordPress/WordPress/commit/d345fe2

Change History (5)

#1 @Hareesh Pillai
2 months ago

  • Keywords reporter-feedback php81 added

Hi @michaing, Welcome to Core Trac.
Thanks for creating the ticket.

Please share the WordPress version in which you noticed these warnings. Also, could you confirm if these warnings are still present while using a default theme (say, Twenty Twenty One) and all plugins disabled?

#2 @michaing
2 months ago

Issues observed on latest WordPress v5.8.2. The second one has been fixed already in unreleased upstream code, the first is a declaration issue in the core code, hence not related to any plugin or theme:

These classes implement IteratorAggregate and ArrayAccess APIs:

And the return type definitions do not match for all contained functions. It seems to be even boolean vs bool in the API is seen as difference here. But in some cases they are indeed different, e.g. offsetGet with string|null vs mixed in the API.

I think I can send a PR to have this fixed.

#3 @hellofromTonya
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hello @michaing,

Welcome to WordPress Core's Trac!

Fixes for PHP 8.1 incompatibilities started in WordPress 5.9 release cycle and did not ship in 5.8.2. Identification and then resolution is ongoing and being tracked in #53635.

The Request deprecation notices are fixed in that project though not yet released. Issues can be explored and raised here https://github.com/WordPress/Requests/issues.

#4 @michaing
2 months ago

I see, many thanks for the info and the dedicated repository. Looks like it currently it is solved via #[ReturnTypeWillChange] in most cases.

I'm looking forward to WordPress 5.9 then and keep an eye on the linked ticket and repository :).

Best regards,

Micha

Last edited 2 months ago by michaing (previous) (diff)

#5 @jrf
8 weeks ago

Related: #54504

Note: See TracTickets for help on using tickets.