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:xampphtdocswordpresswp-includeswidgets.php:1261
Stack trace:
#0
D:xampphtdocswordpresswp-includeswidgets.php(1261):
array_merge(wp_inactive_widgets: Array, sidebar-1: Array, sidebar-2:
Array, sidebar-3: Array)
#1
D:xampphtdocswordpresswp-includeswidgets.php(1216):
retrieve_widgets(true)
#2
D:xampphtdocswordpresswp-includesclass-wp-hook.php(289):
_wp_sidebars_changed('Twenty Twenty')
#3 D:xampphtdocswordpresswp-includesclass-wp-hook.php(311):
WP_Hook->apply_filters(NULL, Array)
#4
D:xampphtdocswordpresswp-includesplugin.php(478):
WP_Hook->do_action(Array)
#5
D:xampphtdocswordpresswp-includestheme.php(2974):
do_action('after_switch_th...', 'Twenty Twenty', Object(WP_Theme))
#6
D:xampphtdocswordpresswp-includesclass-wp-hook.php(287):
check_theme_switched('')
#7
D:xampphtdocswordpresswp-includesclass-wp-hook.php(311):
WP_Hook->apply_filters(NULL, Array)
#8
D:xampphtdocswordpresswp-includesplugin.php(478):
WP_Hook->do_action(Array)
#9
D:xampphtdocswordpresswp-settings.php(540): do_action('init')
#10
D:xampphtdocswordpresswp-config.php(90):
require_once('D:\xampp\htdocs...')
#11
D:xampphtdocswordpresswp-load.php(37):
require_once('D:\xampp\htdocs...')
#12
D:xampphtdocswordpresswp-blog-header.php(13):
require_once('D:\xampp\htdocs...')
#13
D:xampphtdocswordpressindex.php(17):
require('D:\xampp\htdocs...')
#14 {main} thrown in
D:xampphtdocswordpresswp-includeswidgets.php on line 1261
5
Answers
This is a poorly asked question as you have provided no context around the error message presented. 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:This is because
call_user_func_array
will interpret the top-level array keys as parameter names to be passed into thearray_merge
, and these keys will not match the function arguments.The solution here is to use
array_values
to strip away the keys first:The following worked for me when I ran into these issues on my Bluehost WordPress site:
8.0
to7.4
using theMultiPHP Manager
5.3
to5.9
viawp-admin
7.4
to8.1
using theMultiPHP Manager
Recommendation: just install the latest version of the composer in Linux and define it globally and run it on the project directory and the issue is resolved.
Composer 1.10.1 —-> to ——> Composer version 2.3.4
Hint: if same then revoke the composer.lock and vendor folder and run it again.
Had same issue after upgrading to php 8.x
Fixed with:
I tried
composer update
,composer self-update
everythingbut finally this one fixed my issue:
Change:
to:
This fixed it for me