PHP error reporting

Error reporting in PHP is a very usable option but sometimes you can be buried with “PHP Notice” lines which you don’t need (save space and bandwith).

PHP Notice:  Undefined index: 11 in /home/website/blabla.php on line 52

To turn on reporting on all errors add this line above all other php lines (before error happens)

// Report all PHP errors
error_reporting(E_ALL);

To turn on all errors except E_NOTICE

error_reporting(E_ALL ^ E_NOTICE);

To turn off reporting (not recommended)

error_reporting(0);

To be sure that this will work, place error_reporting right below opening php tag (< ? php) More about this options can be found HERE.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.