How to Set error levels and control errors in php

Source: Internet
Author: User
In Windows: Sometimes a program running normally in other environments reports an error in its own environment. The program reports an Undefinedindex: for example, the following code is available: Undefinedvarialbe: here is a solution found on the Internet: The problem is as follows: 1. where is the problem? 2. How should I modify this code? 3. Do not change the code segment

In Windows: Sometimes a program running normally in other environments reports an error in its own environment. The program reports an Undefined index. For example, the following code is available: Undefined varialbe: here is a solution found on the Internet: The problem is as follows: 1. where is the problem? 2. How should I modify this code? 3. Do not change the code segment

In Windows: Sometimes a program running normally in other environments reports an error in its own environment. The program reports an Undefined index:
For example, the following code is available:
Undefined varialbe:

Here is a solution found on the Internet:
The problem is as follows:
1. Where is the problem?
2. How should I modify this code?
3. without changing the code segment, how can I modify the settings in php. ini to make the original program in 4.3.0 run normally in the 4.3.1 environment? This error message is not displayed.

Solution:

Add one 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

Related error_reporting () functions:
Error_reporting () sets the PHP error level and returns 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,

It may also be caused by intentional behaviors. (For example, an uninitialized variable is automatically initialized to
; Use an uninitialized variable instead of 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

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); // displays a runtime error, which is the same as error_reporting (E_ALL ^ E_NOTICE. Error_reporting (E_ALL); // display all errors

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.