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.

<?php

print_r($greeting);
$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.

instructions

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


definitions

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


Exercise available only for signed users.

Please sign in with your GitHub account, this is necessary to track the progress of the lessons. If you do not have an account yet, now is the time to create an account on Github.