WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 10 months ago

#50913 closed task (blessed)

PHP 8.0: various compatibility fixes — at Version 5

Reported by: jrf Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: General Keywords: php8 has-patch has-dev-note
Focuses: coding-standards Cc:

Description (last modified by SergeyBiryukov)

Once #50902 has been merged, a start can be made to apply fixes to WP core to fix the test failures on PHP 8.0.

Rather than opening a new ticket for every single patch, I'm proposing to use this ticket 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 8.0 change across the codebase, separate tickets should still be opened.

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

  • #50343 PHP 8: Fix deprecation notices for optional function parameters declared before required parameter
  • #50833 PHP 8: GD resources are GdImage object instances
  • #50897 PHP 8: fix final private methods

When opening a separate ticket, please tag it with the php8 keyword, so these can be easily found using this report: https://core.trac.wordpress.org/query?keywords=~php8

Change History (7)

#1 @SergeyBiryukov
14 months ago

  • Description modified (diff)

@jrf
14 months ago

Fix one fatal "argument must be passed by reference, value given" error. This single patch fixes 96 errors + 62 failures in the unit test run on PHP 8.0.

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


14 months ago

  • Keywords has-patch added

The WP native get_comment() function expects the first argument $comment to be passed by reference.

The PHP array_map() function, however, passes by value, not by reference, resulting in a fatal arguments must be passed by reference, value given error.

The PHP native array_walk() function _does_ pass by reference. Using this prevents the fatal error on PHP 8 and maintains the existing behaviour on PHP < 8.

This patch fixes 96 errors + 62 failures + 3 warnings of the test failures on PHP 8.

Refs:

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

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


14 months ago

As per the documentation of call_user_func_array(), the $param_arr should be a (numerically) indexed array, not a string-keyed array.

As we can use the spread operator in PHP 5.6+, there isn't really any need to use call_user_func_array() anyhow, we can call the array_merge() function directly.

The caveat to this is that the spread operator only works on numerically indexed arrays, so we need to wrap the $sidebars_widgets variable in a call to array_values() when using the spread operator.

Using array_values() in the existing call_user_func_array() call would also have solved this, but the solution now proposed, has the added benefit of getting rid of the overhead of call_user_func_array().

Refs:

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

@jrf
14 months ago

Fix one fatal "ArgumentCountError: array_merge() does not accept unknown named parameters" error. This patch fixes 5 errors in the unit test run on PHP 8.0.

#4 @SergeyBiryukov
14 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#5 @SergeyBiryukov
14 months ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.