Home >Backend Development >PHP Tutorial >PHP error_reporting error level variable comparison table, errorreporting_PHP tutorial
All error messages in PHP can be set using the error_reporting() function:
Its parameters can be expressed in two ways: strings and numbers, with a total of 14 levels. However, I think it seems that other numbers can be used. At first, I thought it referred to a certain error range. Later, I finally found out The rules:
Now, I’ll summarize it as follows:
Numbers | Constant | Description | ||||||||||||||||||||||||||||||||||||||||||
1 | E_ERROR | Fatal error, script execution is interrupted, that is, something unrecognizable appears in the script
|
||||||||||||||||||||||||||||||||||||||||||
2 | E_WARNING | Part of the code is wrong, but it does not affect the overall operation Example: Warning: require_once(E:/include/config_base.php) | ||||||||||||||||||||||||||||||||||||||||||
4 | E_PARSE | The character, variable or ending place is written incorrectly Example: Parse error: syntax error, unexpected $end in | ||||||||||||||||||||||||||||||||||||||||||
8 | E_NOTICE | General notifications, such as undefined variables, etc. Example: Notice: Undefined variable: p in E:webindex.php on line 17 | ||||||||||||||||||||||||||||||||||||||||||
16 | E_CORE_ERROR | A fatal error occurred when starting the PHP process Example: None | ||||||||||||||||||||||||||||||||||||||||||
32 | E_CORE_WARNING | Warning on PHP startup (non-fatal error) Example: None | ||||||||||||||||||||||||||||||||||||||||||
64 | E_COMPILE_ERROR | Compile time fatal error Example: None | ||||||||||||||||||||||||||||||||||||||||||
128 | E_COMPILE_WARNING | Compile time warning level error Example: None | ||||||||||||||||||||||||||||||||||||||||||
256 | E_USER_ERROR | User-defined error message Example: None | ||||||||||||||||||||||||||||||||||||||||||
512 | E_USER_WARNING | User-defined warning message Example: None | ||||||||||||||||||||||||||||||||||||||||||
1024 | E_USER_NOTICE | User-defined reminder message Example: None | ||||||||||||||||||||||||||||||||||||||||||
2047 | E_ALL | All the above error messages, but excluding E_STRICT error message Example: None | ||||||||||||||||||||||||||||||||||||||||||
2048 | E_STRICT | Coding standardization warnings, allowing PHP to suggest how to modify the code to ensure optimal interoperability and forward compatibility. |
The default value of error_reporting variable is E_ALL & ~E_NOTICE
During development, the best value is: E_ALL | E_STRICT
If set to: error_reporting(E_ALL | E_STRICT), it means recording all error information
It may cause a lot of error codes to appear on the website; but it should be said to be a good thing for programmers, who can optimize the code to the optimum; although some non-fatal errors do not affect the operation of the program, they will aggravate the problem of PHP Burden.
Finally, post the English version of the comparison table:
1 | E_ERROR | Fatal run-time errors. Errors that can not be recovered from. Execution of the script is halted |
2 | E_WARNING | Non-fatal run-time errors. Execution of the script is not halted |
4 | E_PARSE | Compile-time parse errors. Parse errors should only be generated by the parser |
8 | E_NOTICE | Run-time notices. The script found something that might be an error, but could also happen when running a script normally |
16 | E_CORE_ERROR | Fatal errors at PHP startup. This is like an E_ERROR in the PHP core |
32 | E_CORE_WARNING | Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core |
64 | E_COMPILE_ERROR | Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine |
128 | E_COMPILE_WARNING | Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine |
256 | E_USER_ERROR | Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error() |
512 | E_USER_WARNING | Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error() |
1024 | E_USER_NOTICE | User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error() |
2048 | E_STRICT | Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code |
4096 | E_RECOVERABLE_ERROR | Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler()) |
8191 | E_ALL | All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0) |
error_reporting()
There are four types of errors and warnings in php. They are:
Usual function errors: 1
Usual warnings: 2
Analysis errors: 4
Comment (Warning to the user, this message can be ignored, but this problem may bring some problems to your code Error): 8
The four numbers after the message are the representation values of the message type, and they are added up as the error reporting level. The reporting level of a province is 7 (i.e. 1+2+4), or any other combination except "Comments". This level can be changed by changing the error reporting instructions in the php3.ini file. It can also be set by changing the php3 error reporting method in the user's httpd.conf file, or at runtime using the scripting language function error_reporting()
Prevent PHP from reporting typos. If it is not closed, there will be errors like this
Warning: preg_match()
It will not appear if it is closed