What is a fatal error in PHP?

widget

Fatal errors crash the program. There are three types of fatal errors in PHP:

  1. Startup fatal error: This error occurs when a system can’t run the code during installation.

  2. Compile time fatal error: This error occurs if a call is made to a non-existent code or variable.

  3. Runtime fatal error: This error occurs while the program is running, and will cause the program to quit.

The following code tried to call a function name without declaring the function. This gives a fatal error:

<?php
name("John", "Smith");
echo 'Success!';
?>

Notice how the print statement is not executed. This is because, as soon as a fatal error is thrown, the code stops compiling.

Solution

  • Look for the undeclared variables as given in the error.
  • If you are using inbuilt functions, ensure that there is no typo and the correct function is called.
  • Check if the spellings are correct.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved