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.
Built from https://develop.svn.wordpress.org/trunk@48839


git-svn-id: http://core.svn.wordpress.org/trunk@48601 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-08-21 21:51:03 +00:00
parent 7ba8aa2bb4
commit 40ea11468b
2 changed files with 2 additions and 2 deletions

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-alpha-48838'; $wp_version = '5.6-alpha-48839';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -1262,7 +1262,7 @@ function retrieve_widgets( $theme_changed = false ) {
$sidebars_widgets = wp_map_sidebars_widgets( $sidebars_widgets ); $sidebars_widgets = wp_map_sidebars_widgets( $sidebars_widgets );
// Find hidden/lost multi-widget instances. // Find hidden/lost multi-widget instances.
$shown_widgets = call_user_func_array( 'array_merge', $sidebars_widgets ); $shown_widgets = array_merge( ...array_values( $sidebars_widgets ) );
$lost_widgets = array_diff( $registered_widgets_ids, $shown_widgets ); $lost_widgets = array_diff( $registered_widgets_ids, $shown_widgets );
foreach ( $lost_widgets as $key => $widget_id ) { foreach ( $lost_widgets as $key => $widget_id ) {