Function Arguments Uniqueness

ID

php.function_arguments_uniqueness

Severity

high

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Php

Tags

reliability, suspicious

Description

Reports a function, method, closure or arrow function declared with two or more parameters that share the same name, for example function f($a, $b, $a). Each duplicated name is flagged once, on the offending parameter.

Rationale

PHP rejects a parameter list with a repeated name at compile time with a fatal error ("Redefinition of parameter $a"), so the declaration can never execute. The mistake usually comes from a copy-paste while editing the signature, where one parameter should have been renamed. Catching it statically turns a runtime fatal into an early, located diagnostic.

<?php
function move($x, $y, $x)        // FLAW — parameter $x declared twice; fatal at compile time
{
    return [$x, $y];
}

function distinct($x, $y, $z)    // OK — every parameter has a unique name
{
    return [$x, $y, $z];
}

Remediation

Rename the duplicated parameter to the name that was intended, or remove the redundant entry if it was added by mistake. Make sure every parameter in the list has a distinct name.