How to fix PHP ArgumentCountError: array_merge() does not accept unknown named parameters?

Recently I have faced an issue in the project while upgrading PHP version 7.* to 8.* and also upgrade composer version 1 from composer 2.

When I checked the pages in the latest version of PHP that used the array_merge(…$this->items) function in PHP 7.4, I got an error like given,

ArgumentCountError: array_merge() does not accept unknown named parameters in Items.php class.

public function getAllItems()
{
    return array_merge(...$this->items);
}

How to fix the issue to work with PHP 8 and Composer 2?

I have just fixed the issue by,
array_merge(…$this->items); to call_user_func_array(‘array_merge’, array_values($this->items));

The final function to fix the issue,

public function getAllItems()
{
   return call_user_func_array('array_merge', array_values($this->items));
}

Using this way, you can fix the ArgumentCountError on the array_merge() method.