How to set php not to prompt notice: 1. Change "error_reporting" in the "php.ini" file to "error_reporting = E_ALL & ~E_NOTICE"; 2. Add the code to the specified page as "error_reporting(E_ALL ^E_NOTICE);".
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
How to set php not to prompt notice?
PHP Turn off Notice error prompts
This article introduces some methods of turning off notice errors in PHP, but it must be said that turning off error prompts , then whether a large number of notice-level errors in the program code will cause PHP performance to decrease
PHP Notice: Undefined variable PHP Notice: Undefined index
Let’s see if you have any defined variables that are used directly. However, when programming PHP, it is not as strict as C. 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.
//error_reporting(E_ALL); error_reporting(E_ALL || ~E_NOTICE); //显示除去 E_NOTICE 之外的所有错误信息
The first means to display all errors, and the second means to display all errors without displaying warnings. We only need to add // in front of the second line and remove // in front of the first line.
Attachment: Detailed explanation of each error report
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 examples are as follows:
if (!$a) { error_reporting(0); ob_start('ob_gzhandler'); } else { error_reporting(E_ALL ^ E_NOTICE); }
It is forbidden to modify the method in php.ini
1. The space provider in the server Modify the configuration file of php.ini in:
Change error_reporting
in the php.ini file to:
error_reporting = E_ALL & ~E_NOTICE
If you are a Good American space user, you cannot To 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
/* 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, we still need to set the error level to E_ALL when developing, and carefully handle every unreasonable code
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to set php not to prompt notice. For more information, please follow other related articles on the PHP Chinese website!