Search code examples
phperror-reporting

Why not to use highest error reporting level in PHP?


I want you to give reasons why someone should not use the highest possible error reporting level in PHP?

Ways to set highest level:

PHP < 5.4:

error_reporting(E_ALL | E_STRICT);

PHP >= 5.4:

error_reporting(E_ALL);

PHP all versions (as recommended for config files):

error_reporting(2147483647);

PHP all versions (my config, -1 will contain all errors and is easy to remember)

error_reporting(-1);

My experiences:

  • there is no reason for low reporting levels
  • never used the error control operator
  • use to convert all errors to exceptions via set_error_handler and customized exception class to overwrite file and line

Solution

  • I personally prefer to code at the highest level of error reporting, and fix all warnings generated by my code. However, I can envisage a couple of reasons why you might want to work at a lower level:

    1. You may be working with legacy code which emits a lot of warnings. If the code works correctly this is not an issue, but the "noise" may be distracting and prevent you from seeing the real problems. In this situation it may be desirable to lower the error reporting level.
    2. In a production environment you may want to log only errors. This has two benefits, it means your error logs contain only critical issues which need attention, and it will save disk space (and reduce disk i/o).

    Off topic aside: In production environment you should run "display_errors = Off" and "error_logging = On" to prevent users from seeing PHP errors (which may contain sensitive information e.g. database connection properties), and collect a log of errors as they occur. So your production error_reporting level and related setting may be different to what you'd prefer to run in development.