What best practices should be followed when handling fatal errors in PHP using register_shutdown_function?

When handling fatal errors in PHP using register_shutdown_function, it is important to log the error details, notify the appropriate parties, and gracefully terminate the script to prevent further issues.

function handleFatalErrors() {
    $error = error_get_last();
    
    if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING])) {
        // Log the error details
        error_log('Fatal Error: ' . $error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line']);
        
        // Notify appropriate parties
        // Example: send an email to the admin
        
        // Terminate the script
        exit(1);
    }
}

register_shutdown_function('handleFatalErrors');