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

// Before PHP 5.4, E_ALL did not include E_STRICT.
error_reporting(E_ALL);

// -1 shows every possible error, even levels added in later PHP versions.
// As of PHP 5.4, E_ALL does the same.
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);

When log_errors is enabled, PHP logs errors through the SAPI logger. A file such as error.log next to the script is used only when error_log is set to that path.

In a development environment, you can also show them on screen:

ini_set('display_errors', 1);

In production, do not display errors:

ini_set('display_errors', 0);

and show a friendly message from an exception or error handler.

Feedback about page:

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



Table Of Contents