๐ŸŽ“ A1Learner
๐Ÿ”
0 of 40 lessons completed

PHP Errors

PHP errors are messages that report problems in a running program. Errors differ in severity.

A warning and the program continues

A missing variable is read here. The warning prints and the next line still runs.

<?php
echo $missing;
echo "Still running\n";

An array passed to echo

An array is passed to echo here. PHP prints the word Array after the warning.

<?php
$colors = ["red", "blue"];
echo $colors, "\n";

A call to a missing function

A function that does not exist is called here. The line after the call never prints.

<?php
dance();
echo "After\n";

Example

<?php
echo $missing;
echo "First clean line\n";
echo "Second clean line\n";

Key points

  • A warning is a report about a problem in the code.
  • The program continues after a warning.
  • A fatal error stops the program at the line where it happens.
  • An error message names the file where the problem happened.
  • An error message names the line where the problem happened.

In this example, the first line reads a missing variable. PHP prints a warning for that line. The program continues after the warning. Two clean lines print after it.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

A program prints a warning and then prints its next line. What does that show?