Home > Backend Development > PHP Tutorial > How to catch Fatal error in php

How to catch Fatal error in php

怪我咯
Release: 2023-03-13 19:38:02
Original
3167 people have browsed it

This article mainly introduces the method of capturing Fatal error in PHP. Use register_shutdown_function to capture Fatal error. Friends who need it can refer to it

Fatal error generally does not need to be captured, but in a complex situation In a program, if a fatal error occurs due to insufficient memory accidentally, it will be difficult to handle.

For example, the fatal error occurs when fetching in the MySQL class. At this time, it is difficult to locate the real problem.

PHP exception handling can be captured through set_error_handler. However, it can only capture NOTICE/WARNING level errors, and there is nothing you can do about E_ERROR.

register_shutdown_function can solve the shortcomings of set_error_handler.

Through thisfunctionregister the program endcallback function, you can catch errors that cannot be caught normally. Then passerror_get_last Judge the error. It will be easier to find problems that are difficult to locate.

The code is as follows:

function shutdown_function()  
{  
    $e = error_get_last();    
    print_r($e);  
}
register_shutdown_function('shutdown_function');
Copy after login

The above is the detailed content of How to catch Fatal error 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