1.2.729. Multiple Definition Of The Same Argument

A method’s signature is holding twice (or more) the same argument. For example, function x ($a, $a) { }.

This is accepted as is by PHP 5, and the last parameter’s value will be assigned to the variable. PHP 7.0 and more recent has dropped this feature, and reports a fatal error when linting the code. However, this is not common programming practise : all arguments should be named differently.

<?php
  function x ($a, $a) { print $a; };
  x(1,2); => display 2

    // special case with a closure :
  function ($a) use ($a) { print $a; };
  x(1,2); => display 2

?>

See also Prepare for PHP 7 error messages (part 3).

1.2.729.1. Suggestions

  • Give different names to different parameters

1.2.729.2. Specs

Short name

Functions/MultipleSameArguments

Rulesets

All, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56

Exakat since

0.8.4

PHP Version

With PHP 7.0 and older

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

class

ClearPHP

all-unique-arguments

Available in

Entreprise Edition, Exakat Cloud