1.2.1377. Used Once Variables (In Scope)¶
This is the list of used once variables, scope by scope. Those variables are used once in a function, a method, a class or a namespace. In any case, this means the variable is read or written, while it should be used at least twice.
Static and global variables are omitted here : they may be used multiple times by having the method being called multiple times.
Blind variables, which are defined in a foreach() structure, are also omitted : the loop will use them multiple time, assigning different values each time.
Parameters that are inherited from parent classes’ methods are also omitted : they are imposed by the structure, and cannot be avoided.
<?php
function foo() {
// The variables below never appear twice, inside foo()
$writtenOnce = 1;
foo($readOnce);
// They do appear again in other functions, or in global space.
}
function bar() {
$writtenOnce = 1;
foo($readOnce);
}
?>
1.2.1377.1. Connex PHP features¶
1.2.1377.1.1. Suggestions¶
Remove the variable
Fix the name of variable
Use the variable a second time in the current scope, at least
1.2.1377.1.2. Specs¶
Short name |
Variables/VariableUsedOnceByContext |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |