How to set php not to display notice warning: 1. Use "ini_set("display_errors", 0); to shield errors; 2. Open the php.ini file and change the value of "display_errors" from on to Just turn it off.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.
How to set php not to display notice warning?
Solution to PHP display Warning and Notice issues
##After PHP is installed, error reporting, The emergence of reminders, warnings, etc., allows us to understand the problems in the program in a timely manner when debugging the PHP program. Then, sometimes we don’t need reminders, warnings, etc. For example, when we use PHP5.5 (or higher) and use the older MySql connection method with the MySql development environment, PHP will prompt: Please use the latest MySql connection method. When you use it to read database content and return it to the front desk as json format (or other), an error will often occur in the content.
How to block this error Well, the methods are as follows:1. Add a shielding error reminder on the page where a reminder, error, or warning may (or has) occurred:
error_reporting(E_ALL ^ E_DEPRECATED);
//In this versionphp5.5, it is no longer recommended to use the old mysqlConnection method
//But speedPHP still uses the old connection method. At this time, php will report an E_deprecated prompt. Turn off the prompt and it will be OK. You can also put //php in deployment mode (non-development mode), but the best solution is to use the latest speedPHPGenerally you can also use the following content to solve some notice warning and other problems
## ini_set("display_errors", 0);error_reporting(E_ALL ^ E_NOTICE );
error_reporting(E_ALL ^ E_WARNING);
2. Open the php.ini file and find the relevant settings (as shown below) ), change on to off to block errors (this method is not recommended):
Sometimes the display_errors of php.ini is still modified. If it doesn’t work, then refer to the following method:
Modify php.ini and change display_errors = On to display_errors = Off, but the result still doesn’t work. After Baidu checked, it turns out that it needs to be set in php-fpm.conf.
Open php-fpm.conf and find:
## ;
Just change the value from 1 to 0.
3. This method is very suitable for those projects that have decided to use a method that will definitely cause reminders or warnings. Block it once and for all:First refer to 2, find the location of the relevant display_errors, change Off to On
Then find the location in the picture below, modify the level you need to report errors, or the level you do not need to reportThe error reporting levels referred to are as follows:
Definition and usage:
error_reporting() sets PHP's Report the error level and return the current level.
Function syntax:
error_reporting(report_level)
If the parameter level is not specified, the current The error level will be returned. The following are possible values for level:
Value Constant Description
1 E_ERROR Fatal runtime error. The error cannot be recovered and execution of the script is suspended.
2 E_WARNING Runtime warning (non-fatal error). Non-fatal runtime error, script execution will not stop.
4 E_PARSE compile-time parsing error. Parsing errors are generated only by the parser.
8 E_NOTICE runtime reminder (these are often caused by bugs in your code, or may be caused by intentional behavior.)
16 E_CORE_ERROR Fatal error during initialization process when PHP starts.
32 E_CORE_WARNING Warning (non-fatal error) during the initialization process when PHP starts.
64 E_COMPILE_ERROR Fatal error during compilation. This is like an E_ERROR being generated by the Zend scripting engine.
128 E_COMPILE_WARNING compile-time warning (non-fatal error). This is like an E_WARNING warning generated by the Zend script engine.
256 E_USER_ERROR User-defined error message. This is like a user-defined warning message by using PHP function trigger_error (programmer sets E_ERROR)
512 E_USER_WARNING. This is like a user-defined reminder message using the PHP function trigger_error (an E_WARNING warning set by the programmer)
1024 E_USER_NOTICE. This is like a standardized warning encoded by
2048 E_STRICT using the PHP function trigger_error (the programmer sets an E_NOTICE). Allows PHP to suggest how to modify the code to ensure optimal interoperability and forward compatibility.
4096 E_RECOVERABLE_ERROR Fatal error in capturing. This is like an E_ERROR, but can be caught by user-defined handler (see also set_error_handler())
8191 E_ALL All errors and warnings (excluding E_STRICT) (E_STRICT will be part of E_ALL as of PHP 6.0)
Example:
Any number of the above options can be connected with "OR" (using OR or |), so that it can be reported All required bugs at all levels.
For example, the following code turns off user-defined errors and warnings, performs certain operations, and then returns to the original error level:
<?php //禁用错误报告 error_reporting(0); //报告运行时错误 error_reporting(E_ERROR | E_WARNING | E_PARSE); //报告所有错误 error_reporting(E_ALL); ?>
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to set php not to display notice warning. For more information, please follow other related articles on the PHP Chinese website!