What are the best practices for handling fatal errors in PHP scripts?

Fatal errors in PHP scripts should be handled carefully to prevent the script from crashing and potentially leaking sensitive information. One common practice is to use try-catch blocks to catch exceptions and gracefully handle errors by logging them or displaying a user-friendly message.

try {
    // Your PHP code that may throw a fatal error
} catch (Throwable $e) {
    // Log the error or display a user-friendly message
    error_log($e->getMessage());
    echo "An error occurred. Please try again later.";
}