1.2.757. Named Arguments And Variadic

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

<?php
   function foo($a, $b) {}

   $args = ['b' => 2];

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

  // Fatal error: positional arguments MUST be before the variadic
  foo(...$args,  1);

  // positional way of laying the arguments
  foo(1, ...$args);
?>

1.2.757.2. Connex PHP features

1.2.757.2.1. Suggestions

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

1.2.757.2.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