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

How to catch Fatal error in PHP

WBOY
Release: 2016-08-08 09:22:09
Original
1170 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 in need can refer to it

Fatal error generally does not need to be captured, but in a complex program, if Fatal errors caused by occasional insufficient memory are difficult to handle. For example, fatal errors occur when fetching in the MySQL class. At this time, it is difficult to locate the real problem.

PHP exception handling can Capture through set_error_handler. However, it can only capture NOTICE/WARNING level errors, and it is powerless for E_ERROR.

register_shutdown_function can solve the shortcomings of set_error_handler.

Register the program end callback function through this function, and you can Capture errors that cannot be caught normally. Then use error_get_last to judge the errors. It is easy to find problems that are difficult to locate.

Copy the code

The code is as follows:function shutdown_function() {

$e = error_get_last();

print_r($e);
}
register_shutdown_function('shutdown_function');


The above introduces the method of catching Fatal error in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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