The error_reporting () function prescribes which error to report. This function sets the error reporting level for the current script. The function returns the old error reporting level.
First you know that the error_reporting () function is used to set the error level and return to the current level. It has 14 error levels, as follows:
1 e_error fatal run-time error. Mistakes cannot be recovered. The execution of the script was paused for 2 e_warning non-fatal run-time errors. The execution of the script does not stop the
4 e_parse compile-time parse error. Parsing errors should only be notified by
the parser to generate 8 E_notice run time.
- E_core_error fatal error in PHP startup. This is like a e_error error in PHP's core, e_core_warning, when it starts in PHP. This is like a fatal compile-time error in the PHP core e_warning warning E_compile_error. This is like a e_error 128 e_compile_warning a non-fatal compile-time error generated by the Zend script engine , which generates a Zend warning e_warning from the 256 script engine. E_ User_error Fatal user-generated error.
the E_user_warning A non-fatal user-generated warning.
1024 E_user_notice User-generated notifications.
2048 E_STRICT notification of running time.
4096 E_recoverable_error catch a fatal error.
8191 E_all to all the errors and warnings.
As if PHP defaults to not turn on the error, so you need to configure the php.ini file:
Change display_errors = off to display_errors = On
Additionally, configure the error level:
error_reporting = E_all Change to:
error_reporting = E_all & ~e_notice
The default for PHP is to show all errors, while some harmless hints we don't need to display, so set as above!
You can also use the PHP code as follows:
<?php
//Disable error reporting, i.e. do not display error
error_reporting (0);
Report run-time Error
error_reporting (E_error | e_warning | E_parse);
Report All Errors
error_reporting (e_all);
? >
Use examples:
A problem is encountered today in learning the CI framework:
A PHP Error was encountered
Severity:notice
message:undefined variable:user
Generally in the default normal php file output an undefined declaration of a variable is not reported wrong, but in the CodeIgniter framework to report errors, which want to integrate add and modify the page in one of the "lazy person" is not convenient, Because it's the beginner who wants to block this error hint in the code. Even the @, but listen to a lot of people say @ will greatly reduce performance ....
Finally suddenly thought, is not codeigniter intentionally let this error message hint out, how should we go to block out this kind of mistake? Accidentally search "How to let CodeIgniter not show notice information?", An epiphany. Error_reporting (E_all) in the entrance index.php; just change it to
Error_reporting (e_all ^ e_notice);
You can screen out this error without affecting other errors.
We may often see such a function in the program
function seterrorreporting ()
{
//read from the 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:
Code to copy the code as follows
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:
Code to copy the code as follows
Error_reporting (E_all & ~e_notice); or error_reporting (e_all ^ e_notice);
or modify PHP.ini:
Code to copy the code as follows
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
Use method:
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);//Display all Errors
error_reporting (0)
error_reporting (255);
is list all prompts
error_reporting (0 );
is not displaying all prompts
recommends using
Error_reporting (7);
Displays only critical errors
1 e_error fatal run-time errors
2 e_warning Runtime Warning (non-fatal error)
4 E_PA RSE compile-time parsing error
8 E_notice run-time Reminders (often bugs, possibly intentional)
E_core_error fatal error during initialization of PHP
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, or possibly intentional)
2048 e_strict Coding standardization Warnings (how to modify to forward compatible)
4096 E_recoverable_error near fatal run-time error, and if not captured, E_error
6143 e_all all errors except e_strict ( PHP6 is 8191, that contains all)