1.2.747. Named Argument And Variadic

Variadic argument must be the last in the list of arguments. Since PHP 8.1, it is possible to use named arguments after a variadic argument.

<?php
  // named arguments may be after the variadic
  foo(...$a, a: 1);

  // positional arguments MUST be before the variadic
  foo(...$a,  1);

  // Normal way
  foo( 1, ...$a);
?>

1.2.747.1. Suggestions

  • Always put the variadic at the end of the argument list

1.2.747.2. Specs

Short name

Php/NamedArgumentAndVariadic

Rulesets

All, Changed Behavior, CompatibilityPHP80, CompatibilityPHP81

Exakat since

2.5.0

PHP Version

With PHP 8.1 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud