Current Location: Home> Latest Articles> PHP Error Levels Explained: Guide to E_WARNING, E_NOTICE, E_ERROR

PHP Error Levels Explained: Guide to E_WARNING, E_NOTICE, E_ERROR

M66 2025-10-21

Overview of PHP Error Levels

In PHP development, error levels determine the severity of an error and how the script responds. Understanding each error level helps in debugging and maintaining code efficiently.

Common PHP Function Error Levels

E_WARNING

  • Error Level: 2
  • Description: Warning type error that does not stop script execution but indicates a potential problem.

E_NOTICE

  • Error Level: 8
  • Description: Notice type error, less severe, usually does not affect script execution.

E_ERROR

  • Error Level: 1
  • Description: Fatal error that immediately stops script execution.

E_PARSE

  • Error Level: 4
  • Description: Syntax error that stops script execution before it runs.

E_COMPILE_ERROR

  • Error Level: 16
  • Description: PHP compiler cannot compile the script, stops execution before running.

E_CORE_ERROR

  • Error Level: 64
  • Description: Core PHP error, stops execution before the script runs.

E_USER_ERROR

  • Error Level: 256
  • Description: Custom error triggered by trigger_error(), can stop script execution.

Practical Example

The following example demonstrates how to handle different error levels:

<?php
// Log errors
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL ^ E_NOTICE);

// Trigger a warning
echo "Warning message";

// Trigger an error
if (false) {
    echo "Error message";
}
?>

Output

Warning message
PHP Fatal error:  Uncaught Error: Division by zero in ...

Summary and Notes

  • The error_reporting() function can be used to set error levels.
  • Some PHP versions may support additional error levels.
  • Proper handling of error levels helps write stable and maintainable PHP applications.