Home  >  Article  >  Backend Development  >  What are the error levels of php?

What are the error levels of php?

青灯夜游
青灯夜游Original
2020-04-25 17:21:102940browse

The following article will introduce you to php error reporting levels. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What are the error levels of php?

error_reporting()

is used to set the PHP error reporting level and return the current level. (PHP 4, PHP 5)

function can set the error_reporting directive at runtime.

PHP has many error levels. Use this function to set the level when the script is running.

If the optional parameter level is not set, error_reporting() will only return the current error reporting level.

Parameter level

New error_reporting level. Can be a bitmask or a named constant.

It is recommended to use named constants to ensure compatibility with future versions. Due to the addition of error levels and the increase in the range of integer values, older integer-based error levels will not always behave as expected.

level possible values ​​(error reporting level in php)

Common: about 15 in total

What are the error levels of php? 15 corresponds exactly to the 15 bits of binary.

It should be noted that the fields in the above table are not static. Different PHP versions may have different values. For details, please refer to PHP predefined constants

Any number of the above options They can all be connected with "OR" (using OR or |), so that all required errors of all levels can be reported.

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

Example:

<?php
     error_reporting(0);                //禁用错误报告
     error_reporting(E_ERROR | E_WARNING | E_PARSE);//报告运行时错误
     error_reporting(E_ALL);            //报告所有错误
     error_reporting(E_ALL ^ E_NOTICE); //除E_NOTICE报告所有错误,是在php.ini的默认设置
     error_reporting(-1);               //报告所有 PHP 错误
     error_reporting(3);                //不报E_NOTICE
     error_reporting(11);               //报告所有错误
     ini_set(&#39;error_reporting&#39;, E_ALL); // 和 error_reporting(E_ALL); 一样
     error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);//表示php错误,警告,语法错误,提醒都返错。
?>

Conversion relationship:

E_All: Decimal is 30719, converted to binary is 111011111111111

E_NOTICE: Decimal is 8, converted to binary is 1000

~ E_NOTICE: Invert E_NOTICE, and it becomes 0111

E_ALL & ~E_NOTICE:: E_ALL and ~E_NOTICE are ANDed, and it becomes 111011111110111. When converted into decimal, it is 30711

. You can see E_ALL Not all errors are displayed. The 12th bit is 0. The weight of this bit is 2 to the 11th power, which is 2048. It is actually the value of E_STRICT, so E_ALL displays all error levels except E_STRICT.

E_ALL & ~E_NOTICE can be seen in binary, from right to left, the 4th and 12th bits are 0, the weight of the 4th bit is 2 to the third power, which is 8, which is the value of E_NOTICE , so all errors except E_STRICT and E_NOTICE are displayed.

For more related knowledge, please pay attention to

PHP Chinese website

! !

The above is the detailed content of What are the error levels of 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