How can custom error handling be implemented in PHP instead of using the "@" symbol?

Using the "@" symbol in PHP to suppress errors is not recommended as it can lead to debugging issues and make it harder to identify problems in the code. Instead, custom error handling can be implemented by using the set_error_handler() function to define a custom error handler function that will be called whenever an error occurs.

// Define custom error handler function
function customErrorHandler($errno, $errstr, $errfile, $errline) {
    // Handle the error based on the error type
    echo "Error: [$errno] $errstr - $errfile:$errline";
}

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

// Code that may produce errors
$file = fopen("non_existent_file.txt", "r");