1.2.1376. Used Once Variables¶
This is the list of used once variables. Such variables are useless. Variables must be used at least twice : once for writing, once for reading, at least. It is recommended to remove them.
In special situations, variables may be used once :
PHP predefined variables, as they are already initialized. They are omitted in this analyze.
Interface function’s arguments, since the function has no body; They are omitted in this analyze.
Dynamically created variables ($$x, ${$this->y} or also using extract), as they are runtime values and can’t be determined at static code time. They are reported for manual review.
Dynamically included files will provide in-scope extra variables.
This rule counts variables at the application level, and not at a method scope level.
<?php
// The variables below never appear again in the code
$writtenOnce = 1;
foo($readOnce);
?>
See also class.
1.2.1376.1. Connex PHP features¶
1.2.1376.1.1. Suggestions¶
Remove the variable
Fix the name of variable
Use the variable a second time, at least
1.2.1376.1.2. Specs¶
Short name |
Variables/VariableUsedOnce |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
High |
Examples |
|
Available in |