Make WordPress Core

Opened 10 months ago

Closed 2 months ago

Last modified 8 weeks ago

#63061 closed task (blessed) (fixed)

Prepare for PHP 8.5

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: General Keywords: php85 has-patch has-dev-note
Focuses: php-compatibility Cc:

Description (last modified by swissspidy)

This is the meta or "epic" ticket that encapsulates PHP 8.5 compatibility.

Previously:

We're going to try a different approach this time around. All tasks relating to PHP 8.5 compatibility (including devops tasks) will be detailed in and handled in individual tickets. This ticket will remain only in the target milestone for tracking purposes. General info about PHP 8.5 can be added to the summary, and tickets for the actual tasks will be created separately and then linked here.

The previous epic tickets served us really well in the early stages of the corresponding release, but subsequently made it extremely difficult to determine the status of any given change, whether it shipped in any given version, and what is required for compatibility without having to read through the entire ticket. Splitting every required task into a separate ticket with its own acceptance criteria and milestone will help greatly in this regard.

General info

PHP 8.5 is scheduled for release in November 2025. Beta can be expected in August and RC around the end of September.

Tickets

  • #63956 - setAccessible deprecations
  • #63957 - Using null as array offsets
  • #63961 - Updating SimplePie
  • #63962 - Fix deprecation notices for __sleep and __wakeup magic methods
  • #64008 - Updating sodium_compat
  • #64047 - NAN coercion warnings
  • #64051 - Updating ID3

Attachments (1)

63061-deprecated-functions.patch (10.2 KB) - added by TobiasBg 4 months ago.
Add PHP version check around deprecated functions

Download all attachments as: .zip

Change History (40)

#1 @johnbillion
8 months ago

  • Milestone changed from Future Release to 6.9

#2 @johnbillion
8 months ago

  • Description modified (diff)

#3 @TobiasBg
5 months ago

PHP 8.5 deprecates non-canonical scalar type casts (boolean|double|integer|binary) deprecated.

In the Core codebase, I found these in 3 separate files, all from external libraries.

For the getID3 library, I created a PR upstream.

Two more occurrences are in the IXR and JSON libraries, which are unmaintained and therefore can be updated directly in Core, for which I created this PR:
https://github.com/WordPress/wordpress-develop/pull/9592

This ticket was mentioned in PR #9592 on WordPress/wordpress-develop by @TobiasBg.


5 months ago
#4

  • Keywords has-patch added

PHP 8.5 deprecates non-canonical scalar type casts (boolean|double|integer|binary). Therefore, their canonical versions should be used.

See https://php.watch/versions/8.5/boolean-double-integer-binary-casts-deprecated.

The changes in this commit are the only non-canonical scalar type cases in Core files that are maintained directly.
Another occurrence has been submitted for getID3 upstream.

This PR is handled as part of https://core.trac.wordpress.org/ticket/63061.

#5 @TobiasBg
5 months ago

#63853 adds PHP 8.5 compat array functions: array_first and array_last.

#6 @SergeyBiryukov
5 months ago

In 60659:

Code Modernization: Replace non-canonical scalar type casts with canonical versions.

PHP 8.5 deprecates four alternative scalar type names in favor of their canonical names:

  • booleanbool
  • doublefloat
  • integerint
  • binarystring

References:

Follow-up to [1346], [11875].

Props TobiasBg, swissspidy, SergeyBiryukov.
See #63061.

@SergeyBiryukov commented on PR #9592:


5 months ago
#7

Thanks for the PR! Merged in r60659.

This ticket was mentioned in PR #9605 on WordPress/wordpress-develop by @vidugupta.


5 months ago
#8

PHP 8.5 deprecates four alternative scalar type names in favor of their canonical names:

  • boolean → bool
  • double → float
  • integer → int
  • binary → string

This PR replaces deprecated casts in the bundled JSON, IXR, and ID3 libraries to ensure forward compatibility and avoid deprecation notices.

Follow-up to [60659].
See Trac: https://core.trac.wordpress.org/ticket/63061

This ticket was mentioned in Slack in #core by vidugupta. View the logs.


5 months ago

@SergeyBiryukov commented on PR #9605:


5 months ago
#10

Hi there, thanks for the PR!

Please note that getID3 is an external library, and there is already a PR available upstream: JamesHeinrich/getID3#469.

#11 @jorbin
5 months ago

In 60672:

General: Add polyfills for new PHP 8.5 array functions: array_first and array_last.

This power couple of function is coming in PHP 8.5: array_first and array_last.

For more information on these functions, check out the PHP RFC at https://wiki.php.net/rfc/array_first_last.

Props tusharbharti, jorbin, peterwilsoncc, mukesh27, johnbillion.
Fixes #63853. See #63061.

#12 @TobiasBg
5 months ago

Several PHP functions that have not been doing anything since PHP 8.0/8.1 will be deprecated in PHP 8.5 and will thus be throwing warnings: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_no-op_functions_from_the_resource_to_object_conversion

The quickest solution should be to only call them conditionally based on a PHP version check, like

( PHP_VERSION_ID < 80100 ) && finfo_close();
( PHP_VERSION_ID < 80000 ) && xml_parser_free();
( PHP_VERSION_ID < 80000 ) && curl_close();
( PHP_VERSION_ID < 80000 ) && curl_share_close();
( PHP_VERSION_ID < 80000 ) && imagedestroy();

in places where they occur (some of which are in external or "originally-external but now WP" libraries).

@TobiasBg
4 months ago

Add PHP version check around deprecated functions

#13 @TobiasBg
4 months ago

I attached a patch that wraps all calls to the mentioned deprecated PHP functions in a PHP version check.

Externally maintained libraries are not included, instead I opened a PR upstream:
SimplePie: https://github.com/simplepie/simplepie/pull/937
Requests: https://github.com/WordPress/Requests/pull/947

#14 @SergeyBiryukov
4 months ago

In 60703:

Code Modernization: Address no-op function deprecations in PHP 8.5.

Several PHP functions that have not been doing anything since PHP 8.0/8.1, specifically:

  • finfo_close() since the ext/fileinfo migration in PHP 8.1
  • xml_parser_free() since the ext/xml migration in PHP 8.0
  • curl_close() since the ext/curl migration in PHP 8.0
  • curl_share_close() since the ext/curl migration in PHP 8.0
  • imagedestroy() since the ext/gd migration in PHP 8.0

will be deprecated in PHP 8.5 and will thus be throwing warnings.

This commit adds conditional checks to only call these functions on the relevant PHP versions.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate no-op functions from the resource to object conversion.

Props TobiasBg, SergeyBiryukov.
See #63061.

#15 @swissspidy
4 months ago

I created some sub-tickets for some more issues as originally requested:

#16 @swissspidy
4 months ago

In 60729:

Code Modernization: Address reflection no-op function deprecations in PHP 8.5.

Reflection*::setAccessible() methods are no-ops since PHP 8.1. This commit adds conditional checks to only call these functions on older PHP versions.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate `Reflection*::setAccessible()`.

Props rishabhwp, swissspidy.
Fixes #63956.
See #63061.

#17 @TobiasBg
4 months ago

SimplePie 1.9.0 with the mentioned PR has been released, see #63961.

#18 @TobiasBg
4 months ago

Another sub-ticket: #63962
(PHP 8.5: Fix deprecation notices for sleep and wakeup magic methods)

#19 @swissspidy
4 months ago

In 60741:

Interactivity API: Fix "Cannot use bool as array" error.

Improves PHP 8.5 compatibility where calling list() on an empty array throws a warning.

Props swissspidy, jonsurrell, mukesh27.
Fixes #63977.
See #63061.

#20 @TobiasBg
4 months ago

#64008 is for updating sodium_compat with a fix for a PHP 8.5 deprecation.

#21 @SergeyBiryukov
4 months ago

In 60796:

Code Modernization: Address __sleep() and __wakeup() deprecations in PHP 8.5.

PHP 8.5 deprecates the __sleep() and __wakeup() magic methods in favor of __serialize() and __unserialize():

Deprecated: The __wakeup() serialization magic method has been deprecated. Implement __unserialize() instead (or in addition, if support for old PHP versions is necessary)

For PHP < 7.4 compatibility, __sleep() and __wakeup() need to be kept for the time being.

This commit moves the logic of __wakeup() methods in core to __unserialize(), and turns the former into wrappers. WordPress core does not use __sleep() methods, so these are the only changes required.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate the __sleep() and __wakeup() magic methods.

Follow-up to [56835], [60787], [60795].

Props TobiasBg, tusharbharti, swissspidy, dmsnell, SergeyBiryukov.
Fixes #63962. See #63061.

#23 @swissspidy
4 months ago

In 60811:

Code Modernization: Avoid NAN coercion/cast deprecation warnings.

Coercing INF or NAN to a string or casting to int is deprecated in PHP 8.5+.

This change addresses two occurrences in core where this was happening.

Props swissspidy.
Fixes #64047. See #63061.

#24 @swissspidy
4 months ago

  • Description modified (diff)

#25 @swissspidy
4 months ago

  • Description modified (diff)

#26 @swissspidy
4 months ago

In 60812:

External Libraries: Backport upstream PHP 8.5 fixes for getID3.

In absence of a new release, this cherry-picks 8cb29233 and dbda40de.

Props swissspidy, vidugupta, TobiasBg, desrosj.
Fixes #64051. See #63061.

@swissspidy commented on PR #9845:


4 months ago
#27

This is very close. A new issue popped up in SimplePie (https://github.com/simplepie/simplepie/pull/949) but otherwise tests all pass without failures and errors.

#28 @swissspidy
3 months ago

In 60952:

Build/Test Tools: Enable testing for PHP 8.5.

With PHP 8.5 due out in November later this year, contributors have been working on ensuring WordPress 6.9 is as compatible as possible. Enough progress has been made during this release cycle where PHPUnit tests now run successfully with no failures reported.

This change enables PHP 8.5 testing throughout Core’s GitHub Action workflows to ensure no new problems are introduced going forward.

Props swissspidy, desrosj.
See #63061.

#29 @desrosj
3 months ago

  • Keywords needs-dev-note added

Is there anything left outstanding for this one? If everything has been addressed, we should prepare a dev note detailing the changes in 8.5 and how they impact WordPress Core, plugin/theme developers, etc.

#30 @westonruter
2 months ago

In 61171:

Tests: Fix unit test failure in PHP 8.5 due using null as an array offset.

This adds is_string() type checks for the $post_status arg passed to both get_post_status_object() and is_post_status_viewable(). This was triggered by Tests_Post_IsPostStatusViewable::test_built_in_and_unregistered_status_types() for the null data set.

Follow-up to [61170].

See #63167, #63061.

#31 @jorbin
2 months ago

With tests passing and no known issues remaining, I think the devnote and updating the PHP Compatibility and WordPress Versions page is all the is necessary to declare beta support in 6.9.

This ticket was mentioned in Slack in #core by welcher. View the logs.


2 months ago

This ticket was mentioned in PR #10498 on WordPress/wordpress-develop by @westonruter.


2 months ago
#33

This avoids a deprecation warning in PHP 8.5:

Using null as an array offset is deprecated, use an empty string instead

/var/www/src/wp-includes/class-wp-date-query.php:516
/var/www/src/wp-includes/class-wp-date-query.php:170
/var/www/src/wp-includes/class-wp-query.php:2138
/var/www/src/wp-includes/class-wp-query.php:3958
/var/www/src/wp-includes/class-wp.php:704
/var/www/src/wp-includes/class-wp.php:824
/var/www/tests/phpunit/includes/abstract-testcase.php:1346
/var/www/tests/phpunit/includes/testcase-canonical.php:303
/var/www/tests/phpunit/tests/canonical.php:68
/var/www/vendor/bin/phpunit:122

Specifically, the issue is that $wpdb->blogs is null when not on a single-site install. So this ensures that the $wpdb->blogs column is only added to the $known_columns array when on multisite.

It also updates the $valid_columns array to only include multisite-related columns when on multisite, namely registered and last_updated.

Lastly, the phpdoc @var tags for $wpdb->blogs, $wpdb->blogmeta, and the other multisite-specific tables have been updated to indicate they may be null.

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

@westonruter commented on PR #10498:


2 months ago
#34

Added a few small nits. I don't think it's in the coding standards, but I prefer to have an empty line before a control structures.

Cool. I'll apply when committing.

@desrosj commented on PR #10498:


2 months ago
#35

I changed the PR description to point to Core-63957 since that's the more specific issue being addressed here.

#36 @westonruter
2 months ago

In 61191:

Code Modernization: Fix instances of using null as an array offset.

This avoids using multisite-specific tables and columns in WP_Date_Query::validate_column() when on a non-multisite install. Attempting to use $wpdb->blogs as an array index when null on a non-multisite install causes a deprecation notice in PHP 8.5. This also updates the multisite table alias in wpdb to make it clear they could be null.

Developed in https://github.com/WordPress/wordpress-develop/pull/10498

Follow-up to [60904], [60809], [37477].

Props westonruter, desrosj.
See #63061.
Fixes #63957.

#37 @desrosj
2 months ago

  • Resolution set to fixed
  • Status changed from new to closed

With RC1 in ~12 hours and no outstanding known issues, I am going to close this one out as fixed.

If someone would be able and willing to draft a developer note, that would be amazing. If not, I will do my best to get one published this week.

#38 @johnbillion
2 months ago

#39 @johnbillion
8 weeks ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.