Undefined variable $%S¶
Description¶
This error appears when a variable is used, aka read, while it was not defined before.
This might be a variable passed by argument to a method; a variable used with a short assignation operator or an argument of the PHP native function compact.
Example¶
<?php
$x += 1;
foo($a);
compact('undefined');
function foo($a) {}
?>
Solutions¶
Use another variable.
Check the variable before usage.
Give a default value to the variable before usage.