PHP: Variable errors

The main rule is that a variable must be declared before the code where it is used. If you do it after, the program simply won't work.


$greeting = 'Father!';

Execution of the program above will exit with error PHP Notice: Undefined variable: greeting. Undefined variable is a reference error, it means that the code uses a name (identificator) that is not defined. And the error output points us to the exact place where the error occured: greeting. Other possible mistakes include trivial typos that may occur when a variable is used or declared.
You can reduce the number of similar errors by using a correctly set editor. Such editor highlights names used without being previously declared and warns you of possible problems.


Find an undeclared variable in the program and declare it with the value 'Dragon';


  • Variable - a way to store information and give it a name to be reused in code later.

If you got stuck and don't know what to do, you can ask a question in our huge and friendly community