How can PHP handle Fatal Errors without providing specific error messages?

PHP can handle Fatal Errors without providing specific error messages by using a custom error handler function. This function can be used to catch fatal errors, log them, and display a generic error message to the user. By setting this custom error handler, PHP can gracefully handle fatal errors without revealing detailed error messages to the end user.

function customErrorHandler($errno, $errstr, $errfile, $errline) {
    // Log the error
    error_log("Fatal Error: $errstr in $errfile on line $errline");

    // Display a generic error message to the user
    echo "An error occurred. Please try again later.";
}

// Set the custom error handler
set_error_handler("customErrorHandler");

// Trigger a fatal error to test the custom error handler
undefinedFunction();