Setting error reporting and where to display them

suggest change

If it’s not already done in php.ini, error reporting can be set dynamically and should be set to allow most errors to be shown:

Syntax

int error_reporting ([ int $level ] )

Examples

// should always be used prior to 5.4
error_reporting(E_ALL);

// -1 will show every possible error, even when new levels and constants are added 
// in future PHP versions. E_ALL does the same up to 5.4.
error_reporting(-1);

// without notices
error_reporting(E_ALL & ~E_NOTICE);

// only warnings and notices.
// for the sake of example, one shouldn't report only those
error_reporting(E_WARNING | E_NOTICE);

errors will be logged by default by php, normally in a error.log file at the same level than the running script.

in development environment, one can also show them on screen:

ini_set('display_errors', 1);

in production however, one should

ini_set('display_errors', 0);

and show a friendly problem message through the use of an Exception or Error handler.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents