We may often see such a function in the program
The code is as follows |
Copy Code |
function seterrorreporting () { To read from a configuration file whether it is currently a development environment if (dev_env = = True) { Ini_set ("error_reprorting", "E_all & ~e_notice"); Ini_set ("Display_errors", "on"); } else { Error_reporting (E_all); Ini_set (' display_errors ', ' off '); Ini_set ("Log_errors", "on"); Ini_set (' error_log ', '/var/log/phperror.log '); } } |
An example is provided:
In the Windows environment: Originally in the php4.3.0 of the program, in the 4.3.1 Why many errors, the general hint is: notice:undefined varialbe: variable name.
For example, code that resembles the following:
The code is as follows |
Copy Code |
if (! $tmp _i) { $tmp _i=10; } |
Running normally in 4.3.0, running in 4.3.1 prompts notice:undefined varialbe:tmp_i
The questions are as follows: 1. Where is the problem?
2. How should this code be modified?
3. Do not change the code, how to modify the settings in the php.ini so that the original in the 4.3.0 program in the 4.3.1 environment to run normally without this error hint.
Solution:
At the beginning of the program, add a sentence:
The code is as follows |
Copy Code |
Error_reporting (E_all & ~e_notice); or error_reporting (e_all ^ e_notice); |
or modify PHP.ini:
The code is as follows |
Copy Code |
error_reporting = E_all & ~e_notice |
About the error_reporting () function: error_reporting () sets the error level for PHP and returns the current level.
; The error report is bitwise. Or add up the numbers to get the error reporting level you want.
; E_all-All errors and warnings
; E_error-Fatal Run-time Error
; E_warning-Runtime Warning (non-fatal error)
; E_parse-Compile-time parse error
; E_notice-Run-time Reminders (these are often caused by bugs in your code, or by intentional behavior). (for example, an uninitialized variable that is automatically initialized to an empty string based on an uninitialized variable)
; E_core_error-fatal error occurred during initialization of PHP
; E_core_warning-Warning (non-fatal error) during initialization during PHP startup
; E_compile_error-Compile-time fatal error
; E_compile_warning-compile-time warnings (non-fatal errors)
; E_user_error-user-generated error message
; E_user_warning-User generated warning message
; E_user_notice-User Generated reminder message
E_notice indicates that the general situation is not recorded and is used only if the program has an error condition, such as attempting to access a nonexistent variable, or calling a stat () function to view a file that does not exist.
E_warning are usually displayed but do not interrupt the execution of the program. This is very effective for debugging. For example: Call Ereg () with the general representation of the problem.
E_error are usually displayed and interrupt program execution. This mask will not be able to trace the memory configuration or other errors.
E_parse parse errors from the syntax.
E_core_error is similar to E_error, but does not include errors caused by the PHP core.
E_core_warning similar to e_warning, but does not include PHP core error warning
How to use:
error_reporting (0);/Disable Error Reporting
Error_reporting (e_all ^ e_notice);//Show all error messages except E_notice
Error_reporting (E_all^e_warning^e_notice)//shows all error messages except e_warning E_notice
Error_reporting (E_error | e_warning | E_parse)//shows Run-time errors, with error_reporting (e_all ^ e_notice), the effect is the same. Error_reporting (E_all);//Show All errors
Error_reporting (0)
Error_reporting (255);
is to list all hints
error_reporting (0);
is to not show all prompts
Recommended Use
Error_reporting (7);
Show only critical errors
1 E_error Fatal Run-time Error
2 e_warning Runtime Warning (non-fatal error)
4 E_parse Compile-time parse error
8 E_notice Runtime Reminders (often bugs or intentional)
E_core_error fatal error during initialization during PHP startup
E_core_warning warning during initialization of PHP (non-fatal error)
E_compile_error compile-time fatal error
128 E_compile_warning Compile-time warning (non-fatal error)
256 e_user_error user-defined fatal error
E_user_warning user-defined warning (non-fatal error)
1024 E_user_notice user-defined reminders (often bugs, possibly intentional)
2048 E_strict Coding Standardization Warning (recommended how to modify to forward compatible)
4096 E_recoverable_error is close to fatal run-time error and is treated as if not captured E_error
6143 e_all All errors except E_strict (8191 in PHP6, including all)