1.2.1262. Undefined Variable¶
Variable that is used before any initialisation.
It is recommended to use a default value for every variable used. When not specified, the default value is set to NULL
by PHP.
Variable may be created in various ways : assignation, arguments, foreach blind variables, static and global variables.
This analysis doesn’t handle dynamic variables, such as $$x
. It also doesn’t handle variables outside a method or function.
<?php
// Adapted from the PHP manual
$var = 'Bob';
$Var = 'Joe';
// The following line may emit a warning : Undefined variable: $undefined
echo "$var, $Var, $undefined"; // outputs "Bob, Joe, "
?>
See also Variable basics.
1.2.1262.2. Connex PHP features¶
1.2.1262.2.1. Suggestions¶
Remove the expression that is using the undefined variable
Fix the variable name
Define the variable by assigning a value to it, before using it
1.2.1262.2.2. Specs¶
Short name |
Variables/UndefinedVariable |
Rulesets |
|
Exakat since |
1.4.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |