array_merge() expects at least 1 parameter, 0 given

Description

Until PHP 7.4, array_merge() always needed at least one argument to execute. This means that using the variadic operator on an empty array yielded no argument, and then, an error.

Since PHP 7.4, array_merge() handles graciously the case of no arguments, by returning an empty array, and not more error.

This applies to array_merge() and array_merge_recursive().

Example

<?php

$array = [];

$array2 = array_merge(...[]);

?>

Solutions

  • Check for non-empty array before using it with array_merge().