error_log(): Available Error Levels and Their Meanings 🪵


The error_log() function in PHP allows you to specify the error level using an optional parameter. You can choose from a range of predefined error levels to categorize your log message appropriately.

Here are the available error levels and their meanings:

  1. 0 or E_ERROR: Critical errors that can’t be recovered from. These typically result in script termination.
  2. 1 or E_WARNING: Non-fatal runtime errors. These won’t stop the script’s execution but should be addressed.
  3. 2 or E_PARSE: Compile-time parse errors. These occur when PHP code is not correctly structured.
  4. 4 or E_NOTICE: Non-fatal errors related to variables, such as using a variable that hasn’t been defined.
  5. 8 or E_CORE_ERROR: Critical errors that occur during PHP’s startup sequence.
  6. 16 or E_CORE_WARNING: Non-fatal errors that occur during PHP’s startup sequence.
  7. 32 or E_COMPILE_ERROR: Critical compile-time errors.
  8. 64 or E_COMPILE_WARNING: Non-fatal compile-time warnings.
  9. 128 or E_USER_ERROR: User-generated error message. You can use this level to log custom errors in your code.
  10. 256 or E_USER_WARNING: User-generated warning message.
  11. 512 or E_USER_NOTICE: User-generated notice message.
  12. 1024 or E_STRICT: Notices that suggest changes in your code to ensure compatibility with future versions of PHP.
  13. 2048 or E_RECOVERABLE_ERROR: Catchable fatal errors.
  14. 4096 or E_DEPRECATED: Notices about deprecated features or functions.
  15. 8192 or E_USER_DEPRECATED: User-generated deprecated feature notice.
  16. 16384 or E_ALL: All errors and warnings, including runtime notices.

To specify the error level when using error_log(), you pass it as the second argument, like this:

error_log("This is a custom error message.", 3); // Log as an error

In this example, 3 corresponds to E_ERROR. You can replace it with any of the values mentioned above to categorize your log message appropriately based on the severity of the message or event you are logging.