This article mainly introduces the error_reporting function usage in PHP detailed introduction of relevant information, the need for friends can refer to the following
The error_reporting function usage in PHP is described in detail
PHP in the processing of errors will use the Error_reporting function, see the most is error_reporting (e_all ^ e_notice), what does this mean? Below we specifically analyze the error_reporting function.
Defining usage
Error_reporting () Sets the error level for PHP and returns the current level.
Grammar
Error_reporting (Report_level)
If the parameter report_level is not specified, the current error level is returned. The following items are possible values for Report_level:
value |
Constants |
Description |
1 |
E_error |
Fatal run-time error. An unrecoverable error. Stops execution of the script. |
2 |
E_warning |
A non-fatal run-time error. The execution of the script does not stop. |
4 |
E_parse |
Compile-time error. |
8 |
E_notice |
Run-time reminders. |
16 |
E_core_error |
Fatal error during PHP startup. This is like a e_error in the PHP core |
32 |
E_core_warning |
Non-fatal error when PHP is started. This is like a e_warning warning in PHP core |
64 |
E_compile_error |
Fatal compile-time error. This is like a e_error generated by the Zend scripting engine |
128 |
E_compile_warning |
Non-fatal compile-time error, generated by the Zend scripting engine a e_warning warning |
256 |
E_user_error |
User-defined fatal error |
512 |
E_user_warning |
User-defined warning (non-fatal error) |
1024 |
E_user_notice |
User-defined reminders (often bugs, may also be intentional) |
2048 |
E_strict |
Coding normalization Warning (recommended how to modify to forward compatible) |
4096 |
E_recoverable_error |
Near-fatal run-time errors, if not captured, are treated as E_error |
8191 |
E_all |
All errors except E_strict |
PHP does not turn on the error by default, so you need to configure the php.ini file:
Change display_errors = Off to display_errors = On
Also configure the error level, because PHP defaults to show all errors, and some harmless hints we do not need, so set the following:
Change error_reporting = E_all to error_reporting = E_all & ~e_notice
Use the example in PHP code:
Tip: Any number of the above options can be used to connect (with OR or |) with or to report all required levels of errors. For example, the following code turns off user-defined errors and warnings, performs certain actions, and then reverts to the original error level:
<?php//Disable error Reporting error_reporting (0); Report run-time error error_reporting (E_error | e_warning | E_parse); Report all Errors error_reporting (E_all);?>
Learn how the Error_reporting function is used, and then look at the error_reporting (e_all ^ e_notice) code, which means that all error messages except E_notice are displayed.