When I try to install any theme to wordpress this error shows up, what should I do?
Fatal error: Uncaught ArgumentCountError: array_merge() does not
accept unknown named parameters in
D:\xampp\htdocs\wordpress\wp-includes\widgets.php:1261
Stack trace:
#0
D:\xampp\htdocs\wordpress\wp-includes\widgets.php(1261):
array_merge(wp_inactive_widgets: Array, sidebar-1: Array, sidebar-2:
Array, sidebar-3: Array)
#1
D:\xampp\htdocs\wordpress\wp-includes\widgets.php(1216):
retrieve_widgets(true)
#2
D:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(289):
_wp_sidebars_changed('Twenty Twenty')
#3 D:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(311):
WP_Hook->apply_filters(NULL, Array)
#4
D:\xampp\htdocs\wordpress\wp-includes\plugin.php(478):
WP_Hook->do_action(Array)
#5
D:\xampp\htdocs\wordpress\wp-includes\theme.php(2974):
do_action('after_switch_th...', 'Twenty Twenty', Object(WP_Theme))
#6
D:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(287):
check_theme_switched('')
#7
D:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(311):
WP_Hook->apply_filters(NULL, Array)
#8
D:\xampp\htdocs\wordpress\wp-includes\plugin.php(478):
WP_Hook->do_action(Array)
#9
D:\xampp\htdocs\wordpress\wp-settings.php(540): do_action('init')
#10
D:\xampp\htdocs\wordpress\wp-config.php(90):
require_once('D:\\xampp\\htdocs...')
#11
D:\xampp\htdocs\wordpress\wp-load.php(37):
require_once('D:\\xampp\\htdocs...')
#12
D:\xampp\htdocs\wordpress\wp-blog-header.php(13):
require_once('D:\\xampp\\htdocs...')
#13
D:\xampp\htdocs\wordpress\index.php(17):
require('D:\\xampp\\htdocs...')
#14 {main} thrown in
D:\xampp\htdocs\wordpress\wp-includes\widgets.php on line 1261
Given the error appears to be coming from within WordPress code, I am guessing you do not have direct control over the underlying function call that is triggering this error. My best guess is that you are running an old version of WordPress on a system with PHP 8.0+ deployed (see explanation below). Either upgrade WordPress or downgrade to PHP 7.4.
For anybody else that comes this way in search of an answer to why this error is thrown in their code, the error is related to a new feature of PHP 8.0 called 'Named Parameters'. In the case of array_merge, the error can be thrown if you invoke it in the following manner, using a string-keyed array:
call_user_func_array('array_merge', [
'key1'=>['abc', 'def'],
'key2'=>['ghi', 'jkl']
]);
-> Error
This is because call_user_func_array will interpret the top-level array keys as parameter names to be passed into the array_merge, and these keys will not match the function arguments.
The solution here is to use array_values to strip away the keys first:
call_user_func_array('array_merge', array_values([
'key1'=>['abc', 'def'],
'key2'=>['ghi', 'jkl']
]));
-> ['abc','def','ghi','jkl']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With