custom error
The code is an example of custom error handling in PHP. It defines a custom error handling function called customError() which will be called when an error occurs. The function takes two parameters: $errno, which is the error number, and $errstr, which is the error message. The function then echoes a message with the error number and error message.
The code then sets this custom error handler function to be used with the set_error_handler() function. This function takes two parameters: the name of the function to be used as the error handler and the error level to be handled by the error handler. In this case, it is set to handle E_WARNING level errors.
After this, the code triggers an error by calling a require statement to include a file that does not exist, 'fileDoesNotExist.txt', this will throw an error because the file does not exist. The error handler function customError() will be called, displaying the message "unfortunately an error happened: [2] fileDoesNotExist.txt: No such file or directory"
<?php
//example of custom error handling
// this function will be called when an error occurs
function customError($errno, $errstr) {
echo "<b>unfortunately an error happened:</b> [$errno] $errstr";
}
// set error handler
set_error_handler("customError", E_WARNING);
// The above function activates the custom error handler,
// and the error handler will be called when an error occurs
// trigger error on false require
require ('fileDoesNotExists.txt'); // this will throw an error because the file does not exist