1.2.1463. array_merge() And Variadic

Always check value in variadic before using it with array_merge() and array_merge_recursive().

Before PHP 7.4, array_merge() and array_merge_recursive() would complain when no argument was provided. As such, using the spread operator on an empty array() would yield no argument, and an error.

<?php

$b = array_merge(...$x);

?>

1.2.1463.1. Suggestions

  • Add a check to the spread variable to ensure it is not empty

  • Append an empty array to to the spread variable to ensure it is not empty

1.2.1463.2. Specs

Short name

Structures/ArrayMergeAndVariadic

Rulesets

All, Analyze

Exakat since

1.9.2

PHP Version

With PHP 7.4 and older

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

variadic

Available in

Entreprise Edition, Exakat Cloud