4 Different Types of Errors in PHP

August 6, 2019

A PHP Error occurs when something is wrong in the PHP code. The error can be as simple as a missing semicolon, or as complex as calling an incorrect variable.

To efficiently resolve a PHP issue in a script, you must understand what kind of problem is occurring.

tutorial on types of php errors

The four types of PHP errors are:

1. Warning Error
2. Notice Error
3. Parse Error
4. Fatal Error

Tip: You can test your PHP scripts online. We used an online service to test the code mentioned in this article.

Warning Error

A warning error in PHP does not stop the script from running. It only warns you that there is a problem, one that is likely to cause bigger issues in the future.

The most common causes of warning errors are:

  • Calling on an external file that does not exist in the directory
  • Wrong parameters in a function

For instance:

echo "Warning error"';
include ("external_file.php");

As there is no “external_file”, the output displays a message, notifying it failed to include it. Still, it doesn’t stop executing the script.

example of warning error

Notice Error

Notice errors are minor errors. They are similar to warning errors, as they also don’t stop code execution. Often, the system is uncertain whether it’s an actual error or regular code. Notice errors usually occur if the script needs access to an undefined variable.


$a="Defined error";
echo "Notice error";
echo $b;

In the script above, we defined a variable ($a), but called on an undefined variable ($b). PHP executes the script but with a notice error message telling you the variable is not defined.

example of php notice error

Parse Error (Syntax)

Parse errors are caused by misused or missing symbols in a syntax. The compiler catches the error and terminates the script.

Parse errors are caused by:

  • Unclosed brackets or quotes
  • Missing or extra semicolons or parentheses
  • Misspellings

For example, the following script would stop execution and signal a parse error:

echo "Red";
echo "Blue";
echo "Green"

It is unable to execute because of the missing semicolon in the third line.

example of parse error in php

Fatal Error

Fatal errors are ones that crash your program and are classified as critical errors. An undefined function or class in the script is the main reason for this type of error.

There are three (3) types of fatal errors:

  1. Startup fatal error (when the system can’t run the code at installation)
  2. Compile time fatal error (when a programmer tries to use nonexistent data)
  3. Runtime fatal error (happens while the program is running, causing the code to stop working completely)

For instance, the following script would result in a fatal error:

function sub()
echo "The sub= ".$sub;

The output tells you why it is unable to compile, as in the image below:

example of fatal error in php


Distinguishing between the four types of PHP errors can help you quickly identify and solve problems in your script. Make sure to pay attention to output messages, as they often report on additional issues or warnings. If you are trying to locate a bug on your website, it is also important to know which PHP version your web server is running.

Was this article helpful?
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Connect to MySQL using PHP
May 6, 2019

To access and add content to a MySQL database, you must first establish a connection between the database and ...
Read more
How To Install PHP 7, 7.2 & 7.3 On CentOS 7
May 24, 2019

PHP is a programming language that's often used to automate server tasks. It's part of the LAMP...
Read more
How to Install PHP 7, 7.2 ,& 7.3 on Ubuntu 18.04
August 6, 2019

PHP is a script-based server-side programming language. PHP is often used to automate server tasks and is the ...
Read more
PHP Error Reporting: How to Enable & Display All Errors / Warnings
August 6, 2019

If a script is not written correctly, or if something unusual happens, PHP can generate an error message. The...
Read more