Make WordPress Core

Opened 3 weeks ago

Last modified 5 days ago

#54730 new task (blessed)

PHP 8.x: various compatibility fixes for WordPress 6.0

Reported by: hellofromTonya Owned by:
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: General Keywords: php8 php81 has-patch has-unit-tests
Focuses: coding-standards Cc:



This ticket will be used as an "epic", allowing a variety of small patches each fixing a specific failure to be added to and committed against this ticket.

For patches addressing all instances of failures related to one specific PHP version (such as PHP 8.0, 8.1, or 8.2) change across the codebase, separate tickets should still be opened.

For an example of issues/patches with separate tickets, see:

  • #53299 PHP 8.1: Update is_serialized function to accept Enums
  • #53465 PHP 8.1.: the default value of the flags parameter for htmlentities() et all needs to be explicitly set

When opening a separate ticket, please tag it with the appropriate PHP version keyword so that these tickets can be easily found:

Change History (8)

This ticket was mentioned in PR #1801 on WordPress/wordpress-develop by anomiex.

3 weeks ago

  • Keywords has-patch added

This fixes a "Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated" warning on PHP 8.1.

PHP has started requiring that built-in method arguments that are not explicitly declared as nullable may no longer be passed null. In this case it seems to make more sense to avoid calling WordPress's own email_exists() function with null, as that method is declared as taking only strings and a null email is never going to exist anyway.

Trac ticket: https://core.trac.wordpress.org/ticket/54730

#2 @prbot
3 weeks ago

hellofromtonya commented on PR #1801:

I see that you've closed https://core.trac.wordpress.org/ticket/53635 without addressing the issue this PR fixes. What's the way forward now?

@anomiex Trac ticket https://core.trac.wordpress.org/ticket/54730 is now open for continuing PHP 8.x compatibility fixes during the 6.0 cycle. I updated the description in this PR to point at the new ticket.

This ticket was mentioned in PR #1556 on WordPress/wordpress-develop by jrfnl.

2 weeks ago

  • Keywords has-unit-tests added

Fixes strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated notices on PHP 8.1.

Impact: 38 of the pre-existing tests are affected by this issue.

Note: trac ticket link below not added yet on purpose while this ticket is still WIP.

Trac ticket: https://core.trac.wordpress.org/ticket/54730

Update: Though this is WIP, adding the new 6.0 ticket to ensure this PR moves forward in the 6.0 cycle.

This ticket was mentioned in PR #1658 on WordPress/wordpress-develop by jrfnl.

2 weeks ago

Potential fix for the below issue, but the fix _may_ have unforeseen side-effects. Needs second opinion from someone with detailed domain knowledge of the XMLRPC functionality.

strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated


Trac ticket: https://core.trac.wordpress.org/ticket/54730

Update: Changed the Trac ticket to the 6.0 one.

#5 @hellofromTonya
12 days ago

Dropping [51968] as a reminder of ongoing architectural decisions needed to resolve remaining known deprecation notices

This changeset ignores (on purpose) "null to nullable" deprecations for select tests. Why? Here are the details:

Adds an expectation for PHP 8.1 "passing null to non-nullable" deprecation notice to select tests where the deprecation is generated by one of the functions in the wp-includes/formatting.php file, either via a filter hook callback or by a direct call.

Instead of haphazardly fixing these issues exposed by the tests, a more structural and all-encompassing solution for input validation should be architected and implemented as otherwise, we'll keep running into similar issues time and again with each new PHP version.

To discourage people from "fixing" these issues now anyway, this commit "hides" nearly all of these issues from the test runs.

Once a more structural solution is designed, these tests and the underlying functions causing the deprecation notices should be revisited and the structural solution put in place.

This ticket was mentioned in PR #2133 on WordPress/wordpress-develop by hellofromtonya.

12 days ago

The PHP native trim() function expects to be passed a string and it is not a nullable parameter. Passing null to it will result in a trim(): Passing null to parameter #1 ($string) of type string is deprecated notice on PHP 8.1.

In the WP_User::get_data_by() static method, the value given is expected to be int or string. However no input validation was done for fields other than the id field.

This PR adds input validation for the field $value to ensure it is a scalar type and if no, bails out returning false. Why is_scalar()? For backwards-compatible, the native behavior of trim() is retained as it coerces non-string scalar types into a string.

Trac ticket: https://core.trac.wordpress.org/ticket/54730


#7 @costdev
8 days ago

Related ticket: #54826

#8 @SergeyBiryukov
5 days ago

In 52585:

Upgrade/Install: Check if the disk_free_space() function exists before calling it.

In PHP 8+, @ no longer suppresses fatal errors:

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE).

Reference: PHP 8: Backward Incompatible Changes.

disk_free_space() may be disabled by hosts, which will throw a fatal error on a call to undefined function.

This change prevents the fatal error, and falls back to false when disk_free_space() is unavailable.

Follow-up to [25540], [25774], [25776], [25831], [25869].

Props costdev, jrf, swb1192, SergeyBiryukov.
Fixes #54826. See #54730.

Note: See TracTickets for help on using tickets.