PHP error_reporting (E_ALL ^ E_NOTICE) Detailed description of the Error Report

Source: Internet
Author: User
Tags php error

This article describes in detail some methods to enable and disable the error message in PHP, error_reporting, and error report PHP error_reporting (E_ALL ^ E_NOTICE). If you need it, please refer to it.

Example:
In Windows: The program that was originally running 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:

The Code is as follows: Copy code
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:


Open the PHP. ini file in the php installation directory.

Find display_errors = On and change it to display_errors = off.
Note: If you have copied the PHP. ini file to the windows directory, you must change display_errors = On in c: windows/php. ini to display_errors = off.

2. How to output a script error message as a log file:

Open the PHP. ini file in the php installation directory.
Find log_errors = off and change it to log_errors = on.
Find error_log = filename and change it to error_log = "D: PHPerrlogphp_error.log" (here, the directory and file name D: PHPerrlogphp_error.log are whatever you want)
Note: If you have copied the PHP. ini file to the windows directory, you must also copy the c: windows/php. ini file.
In addition, php_error.log must have at least the USER's modification and write permissions. Otherwise, the error log cannot be output.

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, or intentional behavior. (For example, an uninitialized variable is used based on the fact that the uninitialized variable is automatically initialized to 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


Can I disable the PHP error prompt? I don't want others to see my program's error.

Answer:
Because PHP. the settings in ini are global. We cannot directly modify the global configuration information for a single user, but you can use the php function error_reporting to adjust the error information output of the script you are running, for example:

The Code is as follows: Copy code

Error_reporting (E_ALL ^ E_NOTICE ^ E_WARNING );

Disable all notice and warning errors.

Put this statement in the function inclusion file of your script, which is usually controlled by config. php or conn. php.

 

The Code is as follows: Copy code
<? Php
// Disable Error Reporting
Error_reporting (0 );
// Report running errors
Error_reporting (E_ERROR | E_WARNING | E_PARSE );
// Report all errors
Error_reporting (E_ALL );
?>

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.