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

What are the three error reporting level types in PHP?

青灯夜游
Release: 2023-03-06 09:28:02
Original
2476 people have browsed it

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   所有的错误、警告和注意信息
Copy after login

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

<html>
    <head><title>测试错误报告</title></head>
    <body>
        <h2>测试错误报告</h2>
        <?php
            /*开启php.ini中的display_errors指令,只有该指令开启如果有错误报告才输出*/
            ini_set(&#39;display_errors&#39;, 1);  
            /*通过error_reporting()函数设置在本脚本中,输出所有级别的错误报告*/
            error_reporting( E_ALL );
            /*“注意(notice)”的报告,不会阻止脚本的执行,并且可能不一定是一个问题 */
            getType( $var );             //调用函数时提供的参数变量没有在之前声明
            /*“警告(warning)”的报告,指示一个问题,但是不会阻止脚本的执行 */
            getType();                      //调用函数时没有提供必要的参数
            /*“错误(error)”的报告,它会终止程序,脚本不会再向下执行 */
            get_Type();                     //调用一个没有被定义的函数
        ?>
    </body>
</html>
Copy after login

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!

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