Home > Backend Development > PHP Tutorial > PHP close Notice error prompt_PHP tutorial

PHP close Notice error prompt_PHP tutorial

WBOY
Release: 2016-07-13 16:56:32
Original
959 people have browsed it

This article introduces some ways to turn off notice errors in PHP, but it has to be said that when turning off error prompts, will a large number of notice-level errors in the program code cause PHP performance to decrease?

PHP Notice: Undefined variable
PHP Notice: Undefined index
Take a look, have you used any defined variables directly? However, when programming PHP, it is not as strict as C++, and this feature is often used when programming. The default setting of PHP is to display these prompts, which will cause the page to not be displayed properly.

The code is as follows
 代码如下 复制代码

//error_reporting(E_ALL);
error_reporting(E_ALL || ~E_NOTICE); //显示除去 E_NOTICE 之外的所有错误信息

Copy code

//error_reporting(E_ALL);

error_reporting(E_ALL || ~E_NOTICE); //Display all error messages except E_NOTICE

The first one represents all errors,

 代码如下 复制代码

error_reporting(0);//禁用错误报告
error_reporting(E_ALL ^ E_NOTICE);//显示除去 E_NOTICE 之外的所有错误信息
error_reporting(E_ALL^E_WARNING^E_NOTICE);//显示除去E_WARNING E_NOTICE 之外的所有错误信息
error_reporting(E_ERROR | E_WARNING | E_PARSE);//显示运行时错误,与error_reporting(E_ALL ^ E_NOTICE);效果相同。
error_reporting(E_ALL);//显示所有错误

The second one represents all errors but no warnings,


We just need to add // in front of the second line and remove // ​​in front of the first line.

 代码如下 复制代码

if (!$a) {
 error_reporting(0);
 ob_start('ob_gzhandler');
} else {
 error_reporting(E_ALL ^ E_NOTICE);
}

Attachment: Detailed explanation of each error report


How to use:

The code is as follows

Copy code

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);.
 代码如下 复制代码
error_reporting = E_ALL & ~E_NOTICE
error_reporting(E_ALL);//Show all errors

 代码如下 复制代码

/* Report all errors except E_NOTICE */
error_reporting(E_ALL ^ E_NOTICE);

Example

if (!$a) { error_reporting(0);
The code is as follows

Copy code
ob_start('ob_gzhandler'); } else { error_reporting(E_ALL ^ ​​E_NOTICE); } Modification methods are prohibited in php.ini 1. Modify the php.ini configuration file in the server by the space provider: Change error_reporting in php.ini file changed to: If you are a Good American space user and cannot operate the php.ini file, you can use the following method to achieve it 2. Add the following code to the page where you want to disable notice error prompts
The code is as follows Copy code
/* Report all errors except E_NOTICE */ error_reporting(E_ALL ^ ​​E_NOTICE); One thing to note is Turning off PHP error output will not turn off the PHP kernel's error processing. If there are a large number of Notice-level errors in the code, it will still reduce the performance of the PHP program. Therefore, when developing, we still need to set the error level to E_ALL and carefully handle every unreasonable code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631601.htmlTechArticleThis article introduces some ways to turn off notice errors in php, but it must be said that turning off error prompts , will a large number of notice-level errors in the program code cause PHP performance...
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