Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the error type and error level of PHP

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to understand the error type and error level of PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Programmers will inevitably make some mistakes in the process of re-development, or errors will occur for other reasons, so it is necessary for us to know what types of errors are in PHP and what error levels are there. You can also click on the free "php error handling" instructional video to learn about it.

PHP error Typ

Errors in PHP programs are generally divided into three categories: syntax errors, execution errors and logic errors.

Grammatical error

Syntax errors are the easiest to encounter and solve in programming, for example, an error message is displayed when a semicolon is omitted. This error stops the execution of the program and displays an error message. We can correct the program according to the error message and then re-execute it.

Syntax error can be said to be one of the most common types of errors we encounter in programming, and I think it is also the easiest to solve; for example, you forget to enter a semicolon or the function syntax is wrong.

In the above example, the second line ends with a semicolon missing, resulting in an error in the output.

After adding the semicolon, the program runs normally, and the output result is 1. From this we can see that when the syntax error, the program will stop to continue to execute, when the syntax error is resolved, the program can continue to execute.

Runtime error

Run-time errors are errors in the process of running the program. It should be noted that there are no errors in syntax, but during re-execution, PHP will warn you that there is something unreasonable in the program. Unlike syntax errors, the program will continue to run down.

Examples are as follows:

In the above example, there is no syntax error, but 0 cannot be used as a divisor, and the result is output:

Logic error

The program with logic error will be executed normally, but the output result is wrong. The root cause occurs in the code we write, and there is no alarm message in the process of program execution. Examples are as follows:

Output result:

From the above example, we can see that the output result is obviously wrong and illogical, and there is no alarm message when there is a logic error. This requires us to be vigilant and not to make logical mistakes.

Expand knowledge: PHP error level

There are both error types and error levels in PHP, which can be defined in php.ini. (click "how does PHP upload files?" After reading it, you will understand! "see how to find php.ini)

The error types in PHP are as follows:

Fatal runtime error, usually unrecoverable, such as a problem caused by memory allocation, which causes the script to terminate and no longer run.

2-E_WARNING-Runtime warning (non-fatal error), only prompts are given, but the script does not stop running.

4-E_PARSE-compile-time syntax parsing errors, generated only by the parser.

8-E_NOTICE-Runtime notification indicates that the script encounters a condition that may appear as an error, but there may be a similar notification in a script that works properly.

16-E_CORE_ERROR-fatal errors that occur during PHP initialization startup, similar to E_ERROR, but generated by the PHP engine core.

64-E_COMPILE_ERROR-fatal compile-time errors, similar to E_ERROR, but generated by the Zend script engine.

Compile-time warnings (non-fatal errors), similar to E_WARNING, but generated by the Zend scripting engine. .

1024-E_STRICT-enable PHP's recommendations for changes to the code to ensure optimal interoperability and forward compatibility.

8192-E_DEPRECATED-Runtime notifications that, when enabled, will warn against code that may not work properly in future releases.

16384-E_USER_DEPRECATED-warning messages generated by the user, similar to E_DEPRECATED, but generated by the user himself using the PHP function trigger_error () in the code.

30719-E_ALL-all error and warning messages except E_STRICT.

This is the end of "how to understand the error types and error levels of PHP". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report