views:

468

answers:

4

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:

error_reporting(E_ALL | E_STRICT);

PHP 6:

error_reporting(E_ALL);

PHP all versions (as recommended for config files):

error_reporting(2147483647);

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
+10  A: 

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.

Jim OHalloran
+2  A: 

I think there is no good reason, except maybe what Jim says in his first point, running legacy code that cannot or won't be changed.

You should most certainly run it at the highest level during development and wipe out every warning and notice unless you have a great reason not to.

If you have a great reason not to fix a notice during development, you should document it and use the error contorl operator to avoid cluttering the logs.

Vinko Vrsalovic
A: 

Besides Jim's points I would always suggest coding with the highest level of error reporting as it should offer you better portability and (questionably) better performance.

Will Morgan
i don't see how performance fits into this, other than the error control operator being slow.
Schnalle
Using the error control operator has a slight performance cost. However the major performance cost is the act of triggering the warning itself (which is then suppressed). I hadn't contemplated this in my original answer, but Will is actually correct, code that emits a lot of warnings (reported or otherwise) may run slower than clean code which emits no warnings. See http://vega.rd.no/articles/php-performance-error-suppression for benchmarks.
Jim OHalloran
A: 

Well from a sys admin PoV...sometimes there is nothing you can do about the code- legacy or new. Some developers don't debug properly and a manager is going to look at you funny if you waste anyone's time with something that doesn't really matter (not sure if this will upset anyone, but if the result is the same before and after, then it doesn't really matter). I for one am very happy I can disable the notices and focus in on any real problems.

Also, this is just a shot in the dark, but maybe there is some way to do something a little fancy with this in terms of debugging by using error_log() calls.

therealsix