PHPerror_reporting (E_ALL ^ E_NOTICE)

Source: Internet
Author: User
In php, we often use the error_reporting function to handle errors. we can see that the most common function is error_reporting (E_ALL ^ E_NOTICE). What does this mean? let's take a look at it now .... in php, we often use the error_reporting function to handle errors. we can see that the most common function is error_reporting (E_ALL ^ E_NOTICE). What does this mean? let's take a look at it.

We may often see such a function in the program. The code is as follows:

Function setErrorReporting () {// read from the configuration file whether it 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 ');}}

Example: in a Windows environment, the program that originally runs normally in php4.3.0 has multiple errors in 4.3.1. the general prompt is: Notice: Undefined varialbe: variable name.

For example, the following code is available:

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

Run normally in 4.3.0. when running 4.3.1, the system prompts 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 code segment. how to modify the settings in php. ini so that the original program in 4.3.0 runs normally in the 4.3.1 environment without the error message.

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

For the error_reporting () function: error_reporting (), set the PHP error level and return the current level.

; Error reports are reported by bit. Or add the numbers to get the expected error report level.

; E_ALL-all errors and warnings

; E_ERROR-fatal runtime error

; E_WARNING-runtime warning (non-fatal error)

; E_PARSE-parsing error during compilation

; E_NOTICE-runtime reminder (these are often caused by bugs in your code or intentional behaviors, such: use an uninitialized variable based on the fact that the uninitialized variable is automatically initialized as an empty string)

; E_CORE_ERROR-fatal error during PHP startup initialization

; E_CORE_WARNING-warning occurred during PHP startup initialization (non-fatal error)

; E_COMPILE_ERROR-fatal error during compilation

; E_COMPILE_WARNING-warning during compilation (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 file is generally not recorded and used only when the program has an error, for example, an attempt to access a variable that does not exist or call the stat () function to view a file that does not exist.

E_WARNING is usually displayed, but the program execution is not interrupted. this is very effective for debugging. for example, call ereg () in a problematic general notation ().

E_ERROR is usually displayed and program execution is interrupted, meaning that memory configuration or other errors cannot be traced using this mask.

E_PARSE parses errors from the syntax.

E_CORE_ERROR is similar to E_ERROR, but does not include errors caused by PHP core.

E_CORE_WARNING is similar to E_WARNING, but does not include PHP core error warnings.

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); // displays all error messages except E_WARNING E_NOTICE.

Error_reporting (E_ERROR | E_WARNING | E_PARSE); // displays a runtime error, which is the same as error_reporting (E_ALL ^ E_NOTICE). error_reporting (E_ALL); // displays all errors.

Error_reporting (0)

Error_reporting (255); lists all the prompts:

Error_reporting (0); do not show all prompts

Recommended: error_reporting (7 );

Only serious errors are displayed:

1 E_ERROR fatal runtime error

2 E_WARNING runtime warning (non-fatal error)

4 E_PARSE parsing error during compilation

8 E_NOTICE runtime reminder (often a bug or intentional)

16 E_CORE_ERROR fatal error during PHP initialization

32 E_CORE_WARNING warning during PHP initialization (non-fatal error)

64 E_COMPILE_ERROR fatal error during compilation

128 E_COMPILE_WARNING warning during compilation (non-fatal error)

256 user_error user-defined fatal error

512 user_warning user-defined warning (non-fatal error)

1024 user-defined notification for E_USER_NOTICE (often bug or intentional)

2048 E_STRICT code standardization warning (how to modify to forward compatibility)

4096 E_RECOVERABLE_ERROR is close to a fatal runtime error. if it is not captured, it is treated as E_ERROR.

6143 all except E_STRICT errors (8191 in PHP6, that is, all errors ).


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.