PHP capture and error_get_last of using exceptions register_shutdown_function

 

register_shutdown_function

Registers a function to be executed when the suspension php, register a callback, it will complete the script execution or exit () after the call.

 

error_get_last

Finally get the error occurred, including the type (error type), message (error message), file (the file where the error occurred), line (line where the error occurred) of an array, or null if there are no errors.

 

Both functions can be used in combination, the program get the error occurred, and logging information.

The following is a simple example:

class errors
{
    /**
     * Callback
     */
    function shutdown()
    {
        // Get Error 
        $ error = error_get_last ();
         IF ( $ error ) {
             // log information 
            var_dump ( $ error );
        }
    }
}
 
class test{
    function test_shutdown()
    {
        // register a shutdown function will be executed when the suspension php 
        register_shutdown_function ([ new new errors (), 'shutdown' ]);
         // call the function test here that does not exist 
        testaa ();
    }
}
$test = new test();
$test->test_shutdown();

 

Guess you like

Origin www.cnblogs.com/woods1815/p/11145464.html