The usage of the error_reporting function in php is described in detail. In php, error_reporting sets the PHP error level and returns the current level. we can set it based on different levels so that we do not want to execute the program when an error occurs outside the domain, in php, error_reporting sets the PHP error level and returns the current level. we can set it based on different levels so that we do not want to execute the program when an error occurs outside the domain, the following describes the usage and parameters of error_reporting.
Basic information
E_NOTICE indicates that it is not recorded in general cases and used only when the program has an error, for example, an attempt to access a non-existent variable or call the stat () function to view a non-existent file.
E_WARNING is usually displayed, but the execution of the program is not interrupted. This is effective for debugging. For example, call ereg () with a problematic regular expression ().
E_ERROR is usually displayed and the program execution is interrupted. This mask cannot be used to trace memory configurations or other errors.
E_PARSE parsing errors from syntax.
E_CORE_ERROR is similar to E_ERROR, but does not include errors caused by the PHP core.
E_CORE_WARNING is similar to E_WARNING, but does not include PHP core error warnings.
Example:
Error_reporting = E_ALL &~ E_NOTICE; display all errors except reminders
Error_reporting = E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR; only an error is displayed.
Error_reporting = E_ERROR: only fatal errors are reported.
Basic settings
Error_reporting = E_ALL &~ E_NOTICE; display all errors except reminders
Example
The code is as follows: |
|
Error_reporting (0 ); // Report simple running errors Error_reporting (E_ERROR | E_WARNING | E_PARSE ); // Reporting E_NOTICE can be good too (to report uninitialized // Variables or catch variable name misspellings ...) Error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE ); // Report all errors before T E_NOTICE // This is the default value set in php. ini Error_reporting (E_ALL ^ E_NOTICE ); // Report all PHP errors (bitwise 63 may be used in PHP 3) Error_reporting (E_ALL ); // Same as error_reporting (E_ALL ); Ini_set ('error _ report', E_ALL );
|
Integer. Indicates the error level of the old PHP. (Returns the old error_reporting level .)
Example in the manual:
Value |
Constant |
Description |
Note |
1 |
E_ERROR(Integer) |
Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. |
|
2 |
E_WARNING(Integer) |
Run-time warnings (non-fatal errors). Execution of the script is not halted. |
|
4 |
E_PARSE(Integer) |
Compile-time parse errors. Parse errors shoshould only be generated by the parser. |
|
8 |
E_NOTICE(Integer) |
Run-time notices. Indicate that the script encountered something that cocould indicate an error, but cocould also happen in the normal course of running a script. |
|
16 |
E_CORE_ERROR(Integer) |
Fatal errors that occur during PHP's initial startup. This is likeE_ERROR, Cannot it is generated by the core of PHP. |
Since PHP 4 |
32 |
E_CORE_WARNING(Integer) |
Warnings (non-fatal errors) that occur during PHP's initial startup. This is likeE_WARNING, Cannot it is generated by the core of PHP. |
Since PHP 4 |
64 |
E_COMPILE_ERROR(Integer) |
Fatal compile-time errors. This is likeE_ERROR, Cannot T it is generated by the Zend Scripting Engine. |
Since PHP 4 |
128 |
E_COMPILE_WARNING(Integer) |
Compile-time warnings (non-fatal errors). This is likeE_WARNING, Cannot T it is generated by the Zend Scripting Engine. |
Since PHP 4 |
256 |
E_USER_ERROR(Integer) |
User-generated error message. This is likeE_ERROR, Cannot it is generated in PHP code by using the PHP function trigger_error (). |
Since PHP 4 |
512 |
E_USER_WARNING(Integer) |
User-generated warning message. This is likeE_WARNING, Cannot it is generated in PHP code by using the PHP function trigger_error (). |
Since PHP 4 |
1024 |
E_USER_NOTICE(Integer) |
User-generated notice message. This is likeE_NOTICE, Cannot it is generated in PHP code by using the PHP function trigger_error (). |
Since PHP 4 |
2048 |
E_STRICT(Integer) |
Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. |
Since PHP 5 |
4096 |
E_RECOVERABLE_ERROR(Integer) |
Catchable fatal error. it indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. if the error is not caught by a user defined handle (see also set_error_handler (), the application aborts as it wasE_ERROR. |
Since PHP 5.2.0 |
8191 |
E_ALL(Integer) |
All errors and warnings, as supported, role t of levelE_STRICTIn PHP <6. |
6143 in PHP 5.2.x and 2047 previusly |
PHP returns the error level and the current level. we can set it based on different levels so that we do not want to execute the program when an error occurs outside the domain...