Different Types of PHP errors?

Php error

Php errors, is a kind of mistake or fault. Error or a warning can we occurred due to wrong syntax, missing files or functions, wrong conditions.

In other words, we can say an php errors comes when you write code carelessly.


Types of errors:-

Mainly there are four types of php errors

  1. Parse Error
  2. Fatal Error
  3. Warnings
  4. Notices


1: Parse Error

Parse error also called syntax error occurs when there is syntax mistake in code. These kinds of errors only generated during compile time and they will stop the expectation of code. The main reason of these kind of errors is writing a code with carelessly.

Common reasons:

  • Missing semicolons
  • Unclosed braces
  • Unclosed quotes
  • Missing or extra parentheses


2: Fatal Error

Fatal errors are the major errors and they stop the code execution immediately without any warning. These kinds of error caused when PHP understand our written code but didn’t provide the output what we are asking to do. In this case user can lose their unsaved data.

Common reasons:

  • Attempt an illegal instruction
  • Attempt an invalid code
  • Call undefined functions



3: Warnings

Warning is kind of messages those indicate that you are doing some wring please fix it. They will not stop the execution.

Common reasons:

  • Include missing files
  • Using incorrect number of parameters


4: Notices

Notices are most like the warning. These are small and non-critical errors and they do not affect code execution. By default, these kinds of errors not display to the users.

Common reasons:

  • Access the undefined variable


Error Handling: –

Error handing necessary to avoid unwanted results on our pages. They also help to increase the security of our script.

  1. Die Statement
  2. Error reporting
  3. Custom error handlers


1: Die Statement

It’s a very common method for error handling. It’s mainly useful when we want to stop the execution and display a message

2: Error reporting

Error reporting is a function having different types of levels.

error_reporting(0);      //Hide all errors

error_reporting(E_ALL);  //Show all errors

error_reporting(-1);     //Show all errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);  // report simple errors

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); //report notices

error_reporting(E_ALL & ~E_NOTICE); //report all errors except notices


3: Custom error handlers

Php provides us an option to define custom error handlers to error handling. There are used defined function called when errors occurred.


  • error_level – required
  • error_message – required
  • error_file – optional
  • error_line – optional
  • error_context – optional