PHP Error reporting

PHP error reporting displays error messages if there are any errors present in the code while running it like parse errors, runtime error etc.. The error reporting can be configured in php.ini file which is the PHP initialization file. In the php.ini file if we navigate to the error reporting section we could see that there are different type of the error level constants present which can be used to display different kinds of errors. This error level constants can be controlled by the bitwise operators

  • | bitwise OR

  • ^ bitwise XOR

  • & bitwise AND

  • ~ bitwise NOT

  • ! boolean NOT

By default, PHP is set to take action on all errors, notices and warnings EXCEPT those related to E_NOTICE and E_STRICT, which together cover best practices and recommended coding standards in PHP. For performance reasons, this is the recommend error reporting setting. Your production server shouldn’t be wasting resources complaining about best practices and coding standards. That’s what development servers and development settings are for.

Error Level Constants:

  • E_ALL – All errors and warnings (includes E_STRICT as of PHP 5.4.0)

  • E_ERROR – fatal run-time errors

  • E_RECOVERABLE_ERROR – almost fatal run-time errors

  • E_WARNING – run-time warnings (non-fatal errors)

  • E_PARSE – compile-time parse errors

  • E_NOTICE – run-time notices (these are warnings which often result a bug in your code, but it’s possible that it was intentional (e.g., using an uninitialized variable and relying on the fact it is automatically initialized to an empty string)

  • E_STRICT – run-time notices, enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code

  • E_CORE_ERROR – fatal errors that occur during PHP’s initial startup

  • E_CORE_WARNING – warnings (non-fatal errors) that occur during PHP’s initial startup

  • E_COMPILE_ERROR – fatal compile-time errors

  • E_COMPILE_WARNING – compile-time warnings (non-fatal errors)

  • E_USER_ERROR – user-generated error message

  • E_USER_WARNING – user-generated warning message

  • E_USER_NOTICE – user-generated notice message

  • E_DEPRECATED – warn about code that will not work in future versions of PHP

  • E_USER_DEPRECATED – user-generated deprecation warnings

The usage of the error level constants can be found in the php.ini file. In the php.ini file go to the error handling and logging section to see the common usage techniques of these error level constants.

All these error constants are assigned to a variable called error_reporting.


If you come up with any doubts while reading through the php.ini file please feel free to comment. Also like always I welcome all the suggestions. Thank you.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s