Error_reporting () Usage in PHP, phperrorreporting
The error_reporting () function specifies which error to report. This function sets the error reporting level for the current script. The function returns the old error reporting level.
The first thing to know is that the error_reporting () function is used to set the error level and return the current level. It has 14 error levels, as follows:
1 e_error fatal Run-time error. The error cannot be recovered. Execution of the script is paused 2 e_warning non-fatal run-time error. The execution of the script does not stop 4 e_parse compile-time parsing errors. Parsing errors should only be notified by the parser to generate 8 e_notice Runtime. e_core_error fatal error when PHP is started. This is like a non-fatal error in PHP core E_error32 e_core_warning when PHP is started. This is like a fatal compile-time error in PHP core e_warning warning E_compile_error. This is like creating a e_error128 e_compile_warning non-fatal compile-time error by the Zend scripting engine, which generated a e_warning warning from the Zend scripting engine. E_user_error A fatal user-generated error. e_user_warning a non-fatal user-generated warning. 1024x768 e_user_notice User-generated notifications. 2048 e_strict run time notification. 4096 E_recoverable_error Catch a fatal error. 8191 E_all to all the errors and warnings.
It seems that 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:
error_reporting = E_all instead:
error_reporting = E_all & ~e_notice
The default for PHP is to display all errors, and some harmless hints we do not need to display, so set up as above!
You can also use the following in PHP code:
<?php//Disable error Reporting, that is, error error_reporting (0);//Report Run-time error error_reporting (E_error | e_warning | E_parse);//Report All Errors error_reporting (E_all);? >
Examples of Use:
There are a few problems in the process of learning CI framework today:
Generally in the default normal php file output an undefined declaration of the variable is not reported wrong, but in the CodeIgniter framework to report errors, which for the integration to add and modify the page in one of the "lazy" is very inconvenient, Because it is a beginner, how do you want to block this error in the code? Even with the @, but listen to a lot of people say @ will greatly reduce performance ....
Finally suddenly thought, is not codeigniter intentionally let this error message out, how should we go to block this kind of error? accidentally searched "How to let CodeIgniter not show notice information?", Enlightened. The original is the entrance index.php in the error_reporting (E_all); just change it to
Error_reporting (e_all ^ e_notice);
You can block out this error without affecting other errors.
We may often see such a function in the program
function seterrorreporting () { //reads from the configuration file whether current is the 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 ');} }
To illustrate:
In the Windows environment: Originally in the php4.3.0 running a normal program, in 4.3.1 why many error, the general tip is: notice:undefined varialbe: variable name.
For example, the following code:
Code to copy code as follows
if (! $tmp _i) {
$tmp _i=10;
}
Running normally in 4.3.0, running in 4.3.1 will prompt notice:undefined varialbe:tmp_i
The problem is as follows: 1. Where is the problem?
2. How should I modify this code?
3. Do not change the paragraph code, how to modify the settings in the php.ini so that the original program in the 4.3.0 in the 4.3.1 environment to run normally without this error.
Workaround:
Add a sentence at the beginning of the program:
Code to copy code as follows
Error_reporting (E_all & ~e_notice); or error_reporting (e_all ^ e_notice);
or modify PHP.ini:
Code to copy code as follows
error_reporting = E_all & ~e_notice
For 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 report level you want.
; E_all-All errors and warnings
; E_error-Fatal Run-time error
; E_warning-run-time warning (non-fatal error)
; E_parse-Compile-time parse error
; E_notice-Runtime Reminders (these are often caused by bugs in your code, or by intentional behavior). (e.g., using an uninitialized variable based on the fact that an uninitialized variable is automatically initialized to an empty string)
; E_core_error-fatal error occurred during initialization of PHP startup
; E_core_warning-Warning (non-fatal error) occurred during initialization of PHP startup
; E_compile_error-Compile-time fatal error
; E_compile_warning-Compile-time warning (non-fatal error)
; E_user_error-error message generated by the user
; 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 only used if the program has an error condition, such as attempting to access a nonexistent variable, or calling stat () to view files that do 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 a problematic regular representation.
The e_error is usually displayed, and the program execution is interrupted. This mask cannot be traced to a memory configuration or other error.
E_parse parse the error from the syntax.
E_core_error is similar to E_error, but does not include errors caused by 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);//Display all error messages except E_notice
Error_reporting (E_all^e_warning^e_notice);//Displays all error messages except e_warning E_notice
Error_reporting (E_error | e_warning | E_parse);//Display run-time errors with error_reporting (e_all ^ e_notice); Error_reporting (E_all);//Show All errors
Error_reporting (0)
Error_reporting (255);
is to list all tips
error_reporting (0);
is not to show all hints
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, may also be intentional)
E_core_error PHP startup fatal error during initialization
e_core_warning PHP Startup warnings during initialization (non-fatal error)
E_compile_error compile-time fatal error
E_compile_warning Compile-time warning (non-fatal error)
E_user_error user-defined fatal error
E_user_warning user-defined warning (non-fatal error)
1024x768 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 error, if not captured, is considered the same as E_error
6143 e_all All errors except E_strict (8191 in PHP6, including all)
http://www.bkjia.com/PHPjc/1050138.html www.bkjia.com true http://www.bkjia.com/PHPjc/1050138.html techarticle error_reporting () usage in PHP is explained in detail, and the phperrorreporting error_reporting () function specifies which error to report. This function sets the error reporting level for the current script. The function returns the old error ...