Solution – PHP – “Notice: Undefined Variable”

If you’re here, it’s probably because you’ve come across an error like this in your PHP Application.

 Notice: Undefined variable: variable_name in /index.php on line 3

The reason this type of thing happens is because you are attempting to use a variable before you have defined it. If you were to run the code example below, you would see a similar error occur.

echo $variable_name;
$variable_name = 'Variable Name';

You will see that $variable_name is not defined until after you actually use it.

Leave a Reply