PHP error_reporting(E_ALL ^ ​​E_NOTICE) error report detailed description_PHP tutorial

WBOY
Release: 2016-07-20 11:11:04
Original
1122 people have browsed it

This article introduces in detail a summary of some methods for turning on and off error prompts in PHP, error_reporting, and error reporting PHP error_reporting (E_ALL ^ ​​E_NOTICE). Friends in need can refer to it.

Example:
In the 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, the following code:

The code is as follows Copy code
if (!$tmp_i) {
 代码如下 复制代码
if (!$tmp_i) {
$tmp_i=10;
}
$tmp_i=10;

}

It runs normally in 4.3.0, but when it runs in 4.3.1, it will prompt Notice:Undefined varialbe:tmp_i

The problem is as follows:

1. Where is 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 without this error prompt.

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 Copy the PHP.ini file to the windows directory, then you must also change display_errors = On in c:windows/php.ini to display_errors = off

. Second method to output script error prompts as log files:

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" (the directory here And the file name D:PHPerrlogphp_error.log (whatever you choose)

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 modify and write permissions of USER, otherwise the error log cannot be output.

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 alerts (These are often caused by bugs in your code, or may be caused by intentional behavior. (eg: using an uninitialized variable based on the fact that it is automatically initialized to an empty string. variable)
; E_CORE_ERROR - fatal error that occurs during the initialization process of PHP startup
; E_CORE_WARNING - warning (non-fatal error) that occurs during the initialization process of PHP startup
; E_COMPILE_ERROR - compile time Fatal error
; E_COMPILE_WARNING - compile-time warning (non-fatal error)
; E_USER_ERROR - user-generated error message

; 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 errors, which has the same effect as error_reporting(E_ALL ^ ​​E_NOTICE);. E_ALL);//Show all errors

Can I turn off PHP’s error prompts? I don’t want others to see the errors in my program.

Question:
 代码如下 复制代码

error_reporting(E_ALL^E_NOTICE^E_WARNING);

Because of PHP. The settings in .ini are global. We cannot directly modify the global configuration information for an individual user, but you can adjust the error message output of the script you run through the error_reporting PHP function, for example: The code is as follows Copy code error_reporting(E_ALL^E_NOTICE^E_WARNING);

Can turn off all notice and warning level errors.

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

 代码如下 复制代码
//禁用错误报告
error_reporting(0);
//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//报告所有错误
error_reporting(E_ALL);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444671.htmlTechArticleThis article introduces in detail about PHP, error_reporting, error reporting PHP error_reporting (E_ALL ^ ​​E_NOTICE) opening and closing errors A summary of some tips, friends in need can refer to this...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!