Home  >  Article  >  Backend Development  >  How to set warning level in php

How to set warning level in php

藏色散人
藏色散人Original
2021-10-18 10:21:282347browse

How to set the warning level in php: 1. Modify the error_reporting option in php.ini; 2. Use the error_reporting() function in the php page to modify the error level.

How to set warning level in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to set the warning level in php?

How to set php error level

When PHP is running, it will give different prompts for errors of different severity.

eg: When $a is not declared, it is added directly, and the value is NULL. When adding, it is calculated as 0. However, it prompts NOTICE, that is, attention.

We During development, for the sake of standardization of the program, the error reporting level is adjusted to a higher NOTICE level to also report, which helps us quickly locate errors and code specifications. However, after the product is launched and the website is operated, it is not appropriate to Reporting so many errors.

1: This kind of error gives a bad impression to customers
2: When reporting an error, report the absolute path of the website, such as D:\www\1015. Added The risk of being attacked is high
Therefore, after the website is online, the error reporting level should be lowered, reporting fewer errors or even not reporting at all.

Modify the error reporting level:

1: Modify the error_reporting option
in php.ini 2: You can use the error_reporting() function to modify the

error level in the php page. The error level is represented by a binary value: 1111 1111 1111 111 from From left to right, the 1 on each bit represents an error level
Fatal error fatal error: 0000 0000 0000 001 Turn on 1
Warning warning error: 0000 0000 0000 010 Turn on 2
NOTICE warning: 0000 0000 0001 000 Open 8
eg:
  Report them all: error_reporting(11);
  Do not report NOTICE: error_reporting(3);
  No errors are reported: error_reporting(0);

The system replaces the values ​​of each level with system constants for us.

E_ERROR 1
E_WARNING 2
E_NOTICE 8

Report all errors: error_reporting(E_ALL);

##Except NOTICE, all others are reported: error_reporting(E_ALL & ~E_NOTICE );

In development, the error level is higher. In the online product, the error level is lower:


The code is as follows:

  define('DEBUG',true); // 在开发时,声明一个DEBUG模式 
    if(defined('DEBUG')) { //检测到处于开发模式 
    error_reporting(E_ALL); 
    } else { 
    error_reporting(0); 
    }

Recommended Study: "

PHP Video Tutorial"

The above is the detailed content of How to set warning level in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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