skip to Main Content

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


  1. 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:

    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']
    
    Login or Signup to reply.
  2. The following worked for me when I ran into these issues on my Bluehost WordPress site:

    1. Downgrade PHP from 8.0 to 7.4 using the MultiPHP Manager
    2. Upgrade WordPress from 5.3 to 5.9 via wp-admin
    3. Upgrade PHP from 7.4 to 8.1 using the MultiPHP Manager
    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. Had same issue after upgrading to php 8.x

    Fixed with:

    sudo composer self-update
    
    Login or Signup to reply.
  5. I tried composer update, composer self-update everything
    but finally this one fixed my issue:

    Change:

    $choices = call_user_func_array( 'array_merge', $choices ); 
    

    to:

    $choices = call_user_func_array( 'array_merge', array_values($choices) );
    

    This fixed it for me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search