PHP error_reporting Explained: Configuration, Error Levels, and Best Practices
Introduction
The error_reporting directive controls which types of PHP errors, warnings, notices, and deprecation messages are reported during script execution. Unlike display_errors, which determines whether errors are shown in the browser, error_reporting determines which error levels PHP processes.
Choosing an appropriate error reporting level helps developers identify problems during development while reducing unnecessary output in production environments.
This guide explains how error_reporting works, how to configure common error levels, and recommended settings for different environments.
Test Environment
What Is error_reporting?
The error_reporting directive specifies which PHP error types should be reported.
Example:
error_reporting = E_ALL
This setting instructs PHP to report all available error levels, including errors, warnings, notices, and deprecation messages.
How error_reporting Works
The error is first filtered by error_reporting. Any reported errors can then be displayed in the browser or written to a log, depending on your other PHP settings.
Check the Current Value
Run:
Example:
error_reporting => 32767 => 32767
Or verify using:
Search for:
error_reporting
Locate the Active php.ini File
Example:
Loaded Configuration File: /etc/php.ini
If you are using PHP-FPM, edit the configuration file used by PHP-FPM.
Change error_reporting
Open the configuration file:
Find:
error_reporting = E_ALL
Or specify a different level if required.
Save the file and restart PHP-FPM:
Common Error Levels
For most modern PHP applications, E_ALL is the recommended setting during development.
Development vs Production
Development
Recommended:
This configuration reports every available error and displays it immediately, making debugging easier.
Production
Recommended:
Errors are still detected and recorded, but visitors do not see internal error messages.
error_reporting vs display_errors
These two directives serve different purposes.
For example:
PHP continues to detect all errors, but they remain hidden from users.
Numeric Values
Some systems display a numeric value instead of E_ALL.
For example:
32767
In modern PHP versions, this numeric value corresponds to E_ALL.
Using the named constant improves readability and is generally recommended.
Common Issues
No Errors Are Displayed
Possible causes include:
display_errors is disabled.
The application suppresses errors.
PHP-FPM has not been restarted after configuration changes.
Too Many Notices
Development environments often display notices and deprecation messages that are useful for improving code quality. Production servers typically keep these messages out of the browser by disabling display_errors while continuing to log them.
Best Practices
Use E_ALL during development.
Keep display_errors disabled on production servers.
Enable log_errors so errors are recorded.
Restart PHP-FPM after modifying configuration values.
Review error logs regularly instead of relying only on browser output.
Conclusion
The error_reporting directive determines which PHP errors are detected during script execution. Combined with display_errors and log_errors, it forms the foundation of PHP's error handling system.
For most environments, enabling E_ALL while disabling display_errors on production servers provides a good balance between effective debugging and application security.
Explore More
› PHP opcache.max_accelerated_files Explained: Configuration, Performance, and Best Practices
› PHP opcache.validate_timestamps Explained: Configuration, Code Updates, and Best Practices
› PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices
› PHP opcache.enable Explained: Configuration, Performance, and Best Practices