PHP error_reporting (e_all ^ e_notice) Error Report detailed description

Source: Internet
Author: User
Tags ini parse error php and php error

An example is provided:
In the Windows environment: Originally in the php4.3.0 of the program, in the 4.3.1 Why many errors, the general hint is: notice:undefined varialbe: variable name.

For example, code that resembles the following:

The code is as follows Copy Code
if (! $tmp _i) {
$tmp _i=10;
}

Running normally in 4.3.0, running in 4.3.1 prompts notice:undefined varialbe:tmp_i

The questions are as follows:

1. Where is the problem?
2. How should this code be modified?
3. Do not change the code, how to modify the settings in the php.ini so that the original in the 4.3.0 program in the 4.3.1 environment to run normally without this error hint.

Solution:


Open the php.ini file under the PHP installation directory

Find display_errors = on modified to Display_errors = Off
Note: If you have copied the php.ini file to the Windows directory, you must also modify the Display_errors = on in C:windows/php.ini to Display_errors = Off

Two ways to let script error prompt output as log file:

Open the php.ini file under the PHP installation directory
Find log_errors = off modified to Log_errors = On
Find error_log = filename modified to error_log= "D:phperrlogphp_error.log" (Here's the directory and filename d:phperrlogphp_error.log whatever you take)
Note: If you have copied the php.ini file to the Windows directory, you must also c:windows/php.ini the file.
In addition, Php_error.log must have at least user modification and write permissions, otherwise the error log cannot be exported.

About 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 reporting level you want.
; E_all-All errors and warnings
; E_error-Fatal Run-time Error
; E_warning-Runtime Warning (non-fatal error)
; E_parse-Compile-time parse error
; E_notice-Run-time Reminders (these are often caused by bugs in your code, or by intentional behavior). (for example, an uninitialized variable that is automatically initialized to an empty string based on an uninitialized variable)
; E_core_error-fatal error occurred during initialization of PHP
; E_core_warning-Warning (non-fatal error) during initialization during PHP startup
; E_compile_error-Compile-time fatal error
; E_compile_warning-compile-time warnings (non-fatal errors)
; E_user_error-user-generated error message
; E_user_warning-User generated warning message
; E_user_notice-User Generated reminder message

How to use:
error_reporting (0);/Disable Error Reporting
Error_reporting (e_all ^ e_notice);//Show all error messages except E_notice
Error_reporting (E_all^e_warning^e_notice)//shows all error messages except e_warning E_notice
Error_reporting (E_error | e_warning | E_parse)//shows Run-time errors, with error_reporting (e_all ^ e_notice), the effect is the same. Error_reporting (E_all);//Show All errors


Can I turn off the PHP error prompt? I don't want anyone to see my program's error.

Question Answer:
Since the settings in php.ini are global, we cannot modify the overall configuration information directly for you as a single user, but you can adjust the error message output of the script you are running by error_reporting this PHP function, for example:

The code is as follows Copy Code

Error_reporting (e_all^e_notice^e_warning);

You can turn off all notice and warning-level errors.

Put this statement in the functional inclusion file of your script, usually config.php or conn.php to control the output.

  code is as follows copy code
<?php
/ /Disable Error Reporting
error_reporting (0);
//Report run-time error
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.