(fatal error) "array_merge() does not accept unknown named parameters" in Child Reports

This error seems to be triggered when saving the widgets screen. And in fact I can’t save the widgets screen because the ajax endpoint throws a server 500 error. I assume because of this error.

PHP Fatal error:  Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in /home/...../wp-content/plugins/mainwp-child-reports/connectors/class-connector-widgets.php:303
Stack trace:
#0 [internal function]: array_merge(wp_inactive_widgets: Array, sidebar1: Array, offcanvas: Array, sidebar_post: Array, front_page_magazine: Array, front_page_podcast: Array, sidebar-video-webinar: Array, sidebar-footer_1_left: Array, sidebar-footer_2_middle: Array, sidebar-footer_3_right: Array)
#1 /home/..../wp-content/plugins/mainwp-child-reports/connectors/class-connector-widgets.php(303): call_user_func_array('array_merge', Array)
#2 /home/...../wp-content/plugins/mainwp-child-reports/connectors/class-connector-widgets.php(181): WP_MainWP_Stream\Connector_Widgets->handle_widget_removal(Array, Array)
#3 /home/.../wp-content/plugins/mainwp-child-reports/connectors/class-connector-widgets.php(147): WP_MainWP_Stream\Connector_Widgets->handle_sidebars_widgets_changes(Array, Array)
#4 [internal function]: WP_MainWP_Stream\Connector_Widgets->callback_update_option_sidebars_widgets(Array, Array, 'sidebars_widget...')
#5 /home/..../wp-content/plugins/mainwp-child-reports/classes/class-connector.php(92): call_user_func_array(Array, Array)
#6 /home/..../wp-includes/class-wp-hook.php(307): WP_MainWP_Stream\Connector->callback(Array, Array, 'sidebars_widget...')
#7 /home/...../wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#8 /home/....../wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#9 /home/....../wp-includes/option.php(530): do_action('update_option_s...', Array, Array, 'sidebars_widget...')
#10 /home/......./wp-includes/widgets.php(1090): update_option('sidebars_widget...', Array)
#11 /home/......./wp-includes/widgets.php(1959): wp_set_sidebars_widgets(Array)
#12 /home/...../wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php(438): wp_assign_widget_to_sidebar('block-5', '')
#13 /home/...../wp-includes/rest-api/class-wp-rest-server.php(1143): WP_REST_Widgets_Controller->delete_item(Object(WP_REST_Request))
#14 /home/....../wp-includes/rest-api/class-wp-rest-server.php(1676): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/widgets/...', Array, NULL)
#15 /home/....../wp-includes/rest-api/class-wp-rest-server.php(1143): WP_REST_Server->serve_batch_request_v1(Object(WP_REST_Request))
#16 /home/...../wp-includes/rest-api/class-wp-rest-server.php(990): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/batch/v1', Array, NULL)
#17 /home/...../wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
#18 /home/....../wp-includes/rest-api.php(394): WP_REST_Server->serve_request('/batch/v1')
#19 /home/....../wp-includes/class-wp-hook.php(307): rest_api_loaded(Object(WP))
#20 /home/....../wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#21 /home/....../wp-includes/plugin.php(524): WP_Hook->do_action(Array)
#22 /home/...../wp-includes/class-wp.php(398): do_action_ref_array('parse_request', Array)
#23 /home/......./wp-includes/class-wp.php(770): WP->parse_request('')
#24 /home/....../wp-includes/functions.php(1330): WP->main('')
#25 /home/...../wp-blog-header.php(16): wp()
#26 /home/....../index.php(17): require('/home/...../t...')
#27 {main}
  thrown in /home/..../wp-content/plugins/mainwp-child-reports/connectors/class-connector-widgets.php on line 303

I have all the latest updates to plugins and WP 6.0.3. It’s on PHP 8.0.12 on a Dreamhost VPS.

I would consider this a critical bug since it prevents saving the widgets screen, I have to disable the plugin to do this. Hopefully a patch can be released very soon.

Thanks!

The solution according to PHP docs is to run array_values() where the array has string keys when passed to call_user_func_array().

In class-connector-widgets.php there are four references to call_user_func_array(). Change from:

$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', $old ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', $new ) );

to

$all_old_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values($old) ) );
$all_new_widget_ids = array_unique( call_user_func_array( 'array_merge', array_values($new) ) );

I suppose you would need some sort of test for PHP 8 here, or test if the array has string keys (assoc) or something like that. But the docs suggest this is a harmless fix that makes it behave properly for backwards compatible situations.

I’ve directly edited the plugin for now, and hope this doesn’t cause some other issue with Child Reports collecting data!

I also confirmed it no longer has errors saving the widgets screen.

Hey @zackw

Thank you for reporting this.

The development team is looking into this, and we will update this thread when we have more information.

@zackw
Can you please try this version and see if it fixes the issue?

Yes! I can save the widgets screen with no problems. I don’t see errors appearing in the log any more.

I’m assuming this fix doesn’t cause issues with the actual data Child Reports is attempting to collect here? Or cause issues for people not running PHP 8? I suppose you’ll do more testing, but this is good for me now.

Maybe you’ll have to check the entire codebase for uses of call_user_func_array since PHP labels this as a breaking change.

1 Like

Great, I’m glad it fixed the issue.

We’ve tested the fix with PHP 7.4 as well, and the widget screen was being saved properly.

The development team will go over the rest of your questions soon.

Update from the development team:

The fix for this issue will not interfere with the Child Reports plugin functionality, including the data collection.
And there will be no problems either regarding the call_user_func_array function.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.