Home  >  Article  >  Backend Development  >  What are the three error reporting level types in PHP?

What are the three error reporting level types in PHP?

青灯夜游
青灯夜游Original
2020-09-29 10:17:242229browse

php The three error reporting levels are: 1. Syntax error; it will prevent the execution of the script. 2. Runtime errors; generally it will not prevent the execution of the PHP script, but it will prevent the current thing to be done and output an error, but the PHP script will continue to execute. 3. Logic error; neither prevents the execution of the script nor outputs an error message.

What are the three error reporting level types in PHP?

Recommended: "PHP Video Tutorial"

1. PHP program errors generally fall into the following three areas

1. Grammar errors

Syntax errors are the most common and easy to fix. For example, if a semicolon is missing in the code, such errors will prevent the execution of the script.

2. Runtime error:

This kind of error generally will not prevent the execution of the php script, but will prevent the current thing to be done and output an error, but the php script will continue to execute. .

3. Logic error:

This kind of error is the most troublesome. It neither prevents the execution of the script nor outputs an error message.

2. PHP error reporting level

   级别常量    错误值    错误报告描述
   E_ERROR 1  致命的运行时错误(阻止脚本执行)
   E_WARNING   2  运行时警告(非致命性错误)
   E_PARSE 4  从语法中解析错误
   E_NOTICE    8  运行时注意消息(可能是或可能不是一个问题)
   E_CORE_ERROR    16 PHP启动时初始化过程中的致命错误
   E_CORE_WARNING  32 PHP启动时初始化过程中的警告(非致命性错)
   E_COMPILE_ERROR 64 编译时致命性错
   E_COMPILE_WARNING   128    编译时警告(非致命性错)
   E_USER_ERROR    256    用户自定义的致命错误
   E_USER_WARNING  512    用户自定义的警告(非致命性错误)
   E_USER_NOTICE   1024   用户自定义的提醒(经常是bug)
   E_STRICT    2048   编码标准化警告(建议如何修改以向前兼容)
   E_ALL   6143   所有的错误、警告和注意信息

3. Adjust the error reporting level

1. display_errors: Whether to enable the level of PHP output error reporting .
Values ​​are: On (default output error report), Off (shield all error messages)
-- The ini_set() function can be called in the php script to dynamically set the php.ini configuration file.
-- For example: ini_set("display_errors", "On"); Display all error messages

2. error_reporting: Set different error level reports
error_reporting = E_ALL & ~E_NOTICE
-- Any unnoticed error can be thrown
error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
-- Only fatal runtime errors, new parsing errors and core errors are considered.
error_reporting = E_ALL & ~(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE)
-- Report all errors except errors caused by the user.
In the php script, the error reporting level can be dynamically set through the error_reporting() function.
Such as: error_reporting(E_ALL);

4. Code testing


    测试错误报告

测试错误报告

Related recommendations:php training

The above is the detailed content of What are the three error reporting level types 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