Unused Parameter
ID |
php.unused_method_parameter |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Php |
Tags |
code-style, unused-code |
Description
Reports function and method parameters that are declared but never read inside the body. A parameter that has no effect on the result is dead weight and usually a leftover from a refactoring.
Rationale
Every parameter is a promise to the caller that the value matters. When the body never reads it, that promise is broken: callers still compute and pass an argument that changes nothing, and the next reader has to verify by hand that the parameter is truly inert. Removing it sharpens the signature, or — when the parameter exposes a real omission — surfaces logic that forgot to use it.
The rule deliberately leaves some parameters alone. Variables interpolated inside double-quoted
strings ("$value", "{$value}") count as used. Variadic parameters (…$rest) and
parameters that begin with an underscore ($_unused) are treated as intentionally ignored.
Methods of a class that extends or implements another type are skipped, because the signature
may be fixed by an inherited or interface contract. Functions that read variables dynamically
(compact, extract, get_defined_vars, func_get_args) are skipped entirely.
<?php
function greet($name, $title) // FLAW — $title is never read
{
return "Hello " . $name;
}
function area($width, $height) // OK — both parameters are used
{
return $width * $height;
}
Remediation
Remove the parameter and update the call sites. If the value was meant to be used, add the missing logic. If the signature is dictated by an external contract you cannot change, prefix the parameter name with an underscore to mark it as intentionally ignored.