Detailed introduction to PHP7 error handling mechanism
Let's take a look at a detailed introduction to the error handling mechanism of PHP7. We have introduced quite a few tutorials on the new features of PHP7. We hope that the article can help all of you.
HP7 implements a global throwable interface. The original Exception and some Errors implement this interface (interface), and define the inheritance structure of exceptions in the form of interfaces. As a result, more Errors in PHP7 become catchable Exceptions and are returned to developers. If they are not caught, they are Errors. If they are caught, they become Exceptions that can be handled within the program. These catchable Errors are usually Errors that will not cause fatal damage to the program, such as a function that does not exist.
1. There are now two exception classes: Exception and Error.
PHP7 now has two exception classes, Exception and Error. Both classes implement a new interface: Throwable. In your exception handling code, type hints may need to be adjusted.
try {
Not_exists_func();
} catch (EngineException $e) {
var_dump($e->getMessage()); }
output:
2. Some fatal errors and recoverable fatal errors are changed to throw Error objects.
Some fatal errors and recoverable fatal errors now report Error objects instead. Error objects are independent from Exception, and they cannot be caught by regular try/catch. Editor's note: You need to register an error handling function, please refer to the RFC below.
3. Syntax errors will throw a ParseError object
Syntax errors will throw a ParseError object, which inherits from the Error object. When handling eval() before, in addition to checking the return value or error_get_last() for potentially error-prone code, you should also capture the ParseError object.
4. If the construction method of the internal object fails, it will always throw an exception
The construction method of internal objects will always report an exception if it fails. Some previous constructors would return NULL or an unusable object.
5. The levels of some E_STRICT errors have been adjusted. <script>ec(2);</script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use