Register_shutdown_function Catch fatal error

Source: Internet
Author: User

Today because of contact with a framework, various try,catch. Throws a fatal error and a syntax error to 500. Try,catch is unable to catch the wrong. And then use the next register_shutdown_function This method, very good
The principle of this method is to call it once before the end of the PHP process. So with Error_get_last(this method, by definition, returns the last error) can be a good catch fatal error

Register_shutdown_function (' shutdown_function ');  
Try
{
    $a = new A ();//This will report fatal error
    Echo 5/0;
}
catch (Exception $e)
{
    echo ' exception capture ';
    Print $e->getmessage ();
}

function shutdown_function ()  
{  
    echo ' catch error ';
    $e = Error_get_last ();    
    Print_r ($e);  

Here I started making a mistake by writing register_shutdown_function to the end. Because the PHP code was executed from beginning to end, the process was interrupted by a fatal error before it was executed to your method, so put him in the beginning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.