WordPress.org

Make WordPress Core

Changeset 48839


Ignore:
Timestamp:
08/21/2020 09:49:02 PM (2 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Fix PHP 8 "ArgumentCountError: array_merge() does not accept unknown named parameters" fatal error in retrieve_widgets().

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().

Props jrf.
See #50913.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets.php

    r48590 r48839  
    12631263
    12641264    // Find hidden/lost multi-widget instances.
    1265     $shown_widgets = call_user_func_array( 'array_merge', $sidebars_widgets );
     1265    $shown_widgets = array_merge( ...array_values( $sidebars_widgets ) );
    12661266    $lost_widgets  = array_diff( $registered_widgets_ids, $shown_widgets );
    12671267
Note: See TracChangeset for help on using the changeset viewer.