1.2.1474. array_merge() And Variadic

Always check the presence of values in a variadic variable, before using it with array_merge() and array_merge_recursive().

Before PHP 7.4, array_merge() and array_merge_recursive() complained 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.1474.2. Connex PHP features

1.2.1474.2.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.1474.2.2. Specs

Short name

Structures/ArrayMergeAndVariadic

Rulesets

All, Analyze, Changed Behavior

Exakat since

1.9.2

PHP Version

With PHP 7.4 and older

Severity

Minor

Time To Fix

Quick (30 mins)

Changed Behavior

PHP 7.4 - More

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud