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

How to catch Fatal error in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:39850browse

Fatal errors generally do not need to be caught, but in a complex program, if a fatal error occurs due to insufficient memory, 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.

By registering the program end callback function with this function, you can catch errors that cannot be caught normally. Then use error_get_last to judge the errors. It will be easier to find problems that are difficult to locate.

Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781814.htmlTechArticleFatal error generally does not need to be caught, but in a complex program, if insufficient memory accidentally occurs, fatal Errors are difficult to handle. For example, fatal errors occur in the MySQL class...
Statement:
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