1.2.1299. Unused Inherited Variable In Closure¶
Some closures forgot to make usage of inherited variables.
Closure <https://www.php.net/manual/en/class.`closure.php>`_ have two separate set of incoming variables : the arguments (between parenthesis) and the inherited variables, in the ‘use’ clause. Inherited variables are extracted from the local environment at creation time, and keep their value until execution.
The reported closures are requesting some local variables, but do not make any usage of them. They may be considered as dead code.
<?php
// In this closure, $y is forgotten, but $u is used.
$a = function ($y) use ($u) { return $u; };
// In this closure, $u is forgotten
$a = function ($y, $z) use ($u) { return $u; };
?>
See also Anonymous functions.
1.2.1299.1. Connex PHP features¶
1.2.1299.1.1. Suggestions¶
Remove the unused inherited variable
Make us of the unused inherited variable
1.2.1299.1.2. Specs¶
Short name |
Functions/UnusedInheritedVariable |
Rulesets |
|
Exakat since |
1.0.11 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |