Home >Backend Development >PHP Tutorial >Detailed description of PHP function error_reporting(E_ALL ^ ​​E_NOTICE)_PHP tutorial

Detailed description of PHP function error_reporting(E_ALL ^ ​​E_NOTICE)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:27:44877browse

For example:

In Windows environment: a program that originally ran normally in php4.3.0, why are there many errors reported in 4.3.1? The general prompt is: Notice: Undefined varialbe: variable name.
For example, there is the following code:

Copy code The code is as follows:

if (!$tmp_i) {
$tmp_i =10;
}

It runs normally in 4.3.0, but when running in 4.3.1, it will prompt Notice: Undefined varialbe: tmp_i
The following problems:
1. What's the problem?
2. How should this code be modified?
3. Without changing the code, how to modify the settings in php.ini so that the original program in 4.3.0 can run normally in the 4.3.1 environment? This error message will not appear.

Solution:

Add a sentence at the beginning of the program:
error_reporting(E_ALL & ~E_NOTICE); or error_reporting(E_ALL ^ ​​E_NOTICE);

or
modify php.ini
error_reporting = E_ALL & ~E_NOTICE

About the error_reporting() function:


error_reporting() sets the error level of PHP and returns the current level.

; Error reporting is bitwise. Or add up the numbers to get the desired error reporting level.
; E_ALL - all errors and warnings
; E_ERROR - fatal runtime errors
; E_WARNING - runtime warnings (non-fatal errors)
; E_PARSE - compile-time parsing errors
; E_NOTICE - runtime reminder (these are often caused by bugs in your code,

; or may be caused by intentional behavior. (eg: automatic initialization of an uninitialized variable to a
;The fact that an empty string is used and an uninitialized variable is used)

; E_CORE_ERROR - Fatal error that occurs during the initialization process when PHP is started
; E_CORE_WARNING - A warning occurs during the initialization process when PHP is started (non-fatal error)
; E_COMPILE_ERROR - Fatal error at compile time
; E_COMPILE_WARNING - Warning at compile time (non-fatal error)
; E_USER_ERROR - Error message generated by user
; E_USER_WARNING - User Generated warning message
; E_USER_NOTICE - User generated reminder message

Usage:

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);//Display all error messages except E_WARNING E_NOTICE
error_reporting(E_ERROR | E_WARNING | E_PARSE);//Display Runtime error, same effect as error_reporting(E_ALL ^ ​​E_NOTICE); error_reporting(E_ALL);//Display all errors.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323729.htmlTechArticleExample: In Windows environment: a program that originally ran normally in php4.3.0 will run normally in 4.3.1 Why are there many errors reported? The general prompt is: Notice: Undefined varialbe: variable name. For example,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn