How to solve error: array_merge() does not accept unknown named parameters

The error “uncaught argumentcounterror: array_merge() does not accept unknown named parameters” occur when you are using PHP 8 and an older version of the composer. To solve this error upgrade the composer to the latest version or downgrade your PHP version to 7.X.

This may also cause some PHP deprecated errors like “Return type of getIterator() should either be compatible with IteratorAggregate::getIterator()”.

Why the error “array_merge() does not accept unknown named parameters”

The error “array_merge() does not accept unknown named parameters” happens when you are using composer 1.X and PHP 8. PHP 8.0 is a major update of the PHP language which contains many new features, changes, and optimizations. See What's New in PHP 8 for more details. 

The composer version 1.X is not compatible with PHP version 8.X. So first check your composer version by running the below command in your terminal.

composer --version

 PHP version can be checked by running the below command.

 php --version

How to solve “array_merge() does not accept unknown named parameters”

To solve the error “array_merge() does not accept unknown named parameters” upgrade the composer to the latest version or downgrade your PHP version to 7.X.

Upgrade the composer version

Composer is a tool for managing dependencies in PHP. You can declare the libraries your project depends on, and it will take care of managing (installing/updating) them. If you are working on Windows, then you can download it directly and run Composer-Setup.exe.

If you are using Ubuntu, run the below command.

composer self-update --2

If the composer self-update not working and you are getting an error like “composer self-update is not defined” when you run the above command, then follow the below steps.

Remove your old composer using the below command.

sudo apt remove composer

Even after removing the composer, a directory with reference will remain in the home folder and it should be removed using the below command.

mv ~/.composer ~/was-composer

Next, install the latest version of Composer by running the below commands.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

You now have a local version that you can run using “php composer.phar”. To make the composer global, change its permissions and make it executable. Then copy it to a directory that lies on your $PATH.

chmod +x composer.phar
sudo mv composer.phar /usr/local/bin/composer

Downgrade the PHP version to 7.X

Another solution to fix the error “array_merge() does not accept unknown named parameters” is to downgrade the PHP version to 7.X.

Run the below commands to add the repository for PHP 7 to your system.

sudo apt update 
sudo apt install software-properties-common 
sudo add-apt-repository ppa:ondrej/php 
sudo apt update 

Then, Install PHP 7.4 using the below commands.

sudo apt install php7.4

Next, we have to set PHP 7.4 as the default PHP version without uninstalling other versions already installed in your system

sudo alternatives --config php

It will show a list of all PHP versions installed as given below.

There are 2 choices for the alternative php (providing /usr/bin/php).
 
  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.1   81        manual mode
Press <enter> to keep the current choice[*], or type selection number:

Enter “1” and press enter to set php7.4 as the default PHP version.

Verify your default PHP version with the following command.

 php --version

Conclusion

To solve the error “uncaught argumentcounterror: array_merge() does not accept unknown named parameters”, upgrade the composer to the latest version or downgrade your PHP version to 7.X. The Composer with version 1.X is not compatible with PHP 8.