Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set php not to display notice warning

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, Xiaobian will bring you about how to set PHP not to display notice warning. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.

Php set not to display notice warning method: 1, through "ini_set("display_errors", 0);" shield error;2, open php.ini file,"display_errors" value from on to off.

Operating environment: Windows 7 system, PHP 7.1 version, DELL G3 computer.

How does PHP not display notice warning?

Fix PHP issues such as Warning and Notice

PHP in the installation, will be set in php.ini file error, alert, warning and other ways to appear, so that we can debug PHP program when the program can understand the problems in time. Then, sometimes we do not need to remind, warning and other content, such as when we use PHP 5.5 (or higher), with MySql development environment, using the older MySql connection, PHP will prompt: Please use the latest MySql connection, when you use it to read database content as json format (or other) return to the foreground, often the content will error

How to block this error, the method is as follows:

1. Add masking error alerts to pages where alerts, errors, or warnings may (or have) occurred:

error_reporting(E_ALL ^ E_DEPRECATED);

//In php5.5, the old mysql connection method is no longer recommended

//but speedPHP still uses the old-fashioned connection method, then php will report E_deprecated prompt, at this time turn off the prompt OK, you can also

//php is placed in deployment mode (not development mode), but the best solution is to use the latest speedPHP

You can also use the following content to solve some problems such as notice waring

ini_set("display_errors", 0);

error_reporting(E_ALL ^ E_NOTICE);

error_reporting(E_ALL ^ E_WARNING);

2, open the php.ini file, find the relevant settings (as shown below), change on to off, you can shield the error (this method is not recommended):

Sometimes modifying the dispaly_errors of php.ini still doesn't work, then refer to the following method:

Change php.ini from display_errors = On to display_errors = Off, and it still doesn't work. Baidu under the original, but also in php-fpm.conf settings.

Open php-fpm.conf and find:

/usr/sbin/sendmail -t -i

0

Change the value from 1 to 0.

3. This approach works well for projects where it has been decided to use some form of blocking that will definitely trigger a reminder or warning, once and for all:

First refer to 2, find the location of the relevant dispaly_errors, and change Off to On

Then find the position below and modify the level you need to report an error, or the level you do not need to report an error.

The error levels referenced are as follows:

Definition and usage:

error_reporting() Sets PHP's error reporting level and returns the current level.

Function syntax:

error_reporting(report_level)

If the parameter level is not specified, the current error level is returned. The following are possible values for level:

value constant description

1 E_ERROR Fatal run error. Error cannot be recovered, pause script execution.

2 E_WARNING Runtime warning (non-fatal error). Nonfatal run error, script execution does not stop.

4 E_PARSE compile-time parsing error. Parsing errors are generated only by the parser.

8 E_NOTICE runtime alerts (these are often caused by bugs in your code, or by intentional behavior)

16 E_CORE_ERROR Fatal error during PHP initialization at startup.

32 E_CORE_WARNING Warning during PHP startup initialization (nonfatal error).

64 E_COMPILE_ERROR Fatal compile time error. This is like an E_ERROR generated by the Zend scripting engine.

128 E_COMPILE_WARNING Compile-time warning (nonfatal error). This is like an E_WARNING warning generated by the Zend scripting engine.

256 E_USER_ERROR User-defined error message. This is like using the PHP function trigger_error (programmer setting E_ERROR)

512 E_USER_WARNING User-defined warning message. This is like using PHP trigger_error (an E_WARNING warning set by the programmer)

1024 E_USER_NOTICE User-defined alert messages. This is like an E_NOTICE set created by using the PHP function trigger_error.

2048 E_STRICT Code Standardized Warning. Allows PHP to suggest how to modify code to ensure optimal interoperability Forward compatibility.

4096 E_RECOVERABLE_ERROR Fatal error opened. This is like an E_ERROR, but can be caught by user-defined handling (see also set_error_handler ())

8191 E_ALL All errors and warnings except E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)

Examples:

Any number of the above options can be connected by OR (OR or| This allows you to report all required levels of errors.

For example, the following code turns off user-defined errors and warnings, performs certain actions, and then reverts to the original error level:

The above is how to set the php to not display notice warning, if there is a similar doubt, you may wish to refer to the above analysis to understand. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report