php error level setting method

怪我咯
Release: 2023-03-14 12:02:01
Original
2697 people have browsed it

In the process of PHP programming, everyone will definitely encounter more or less error reminders. It is these error reminders that guide us to write cleaner code. Today we will first write down the main error types we list. Dig holes, write relevant knowledge about PHP errors and exceptions, and slowly fill the holes.

  • DeprecatedThe lowest level error, the program continues to execute

  • Notice notification level error such as using undeclared variables directly, the program continues to execute

  • Warning Warning level error, you may not get the desired result

  • Fatal error Fatal level error Fatal level error, the program will not execute further

  • Parse error syntax parsing error, the highest level error, even other error messages are not displayed

  • E_USER_related errors User-set related errors

Use the trigger_error() function to set a user-level error/warning/notice information

How to set the error level?

Modify the error level:

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

The error level is represented by a binary value: 1111 1111 1111 111 From left to right, 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 Turn on 8

eg:

 All reported: error_reporting(11);
  Do not report NOTICE: error_reporting(3);
  Do not report any errors: 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);

During development, the error reporting level is higher. When it is online In the product, the error level should be lower: +
The code is as follows:

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

The above is the detailed content of php error level setting method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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