I am aware of the set_error_handler
function.. But I am wondering if it's possible to set a custom error handler for certain user defined functions? Example.
function ArrayToString ($Array){
if (!is_array($Array)){
trigger_error("Not Array", Not_Array); // I know this is invalid syntax but an example
}
return implode (" ",$Array);
}
Then something like:
set_handler_Not_Array(){
//Format with some CSS
echo "The Argument supplied within ".$errline." <br> Inside: ".$errfile." Is not a valid Array";
exit;
}
Is a solution like this possible? Or would I do I have to resort to the current error handling that is in use:
function Error_Handler($errno, $errstr,$error_file,$error_line)
{
$MySQLCheck = "mysql_connect()"; // String to search for
$MySQL = strpos($errstr, $MySQLCheck); // Looks inside the $errstr for the string $MySQLCheck
if ($MySQL !== false) // if Contains the $MySQLCheck
{
unset($errstr); // Unsets the current error message (which usually states username@host
$errstr = "Can Not Connect To Database"; // Changes the error message to something thatdoes not give away username or host.
}
$UndefinedIndex = "Undefined index:"; // String to search for
$Index = strpos($errstr, $UndefinedIndex); // Searches $errstr for the String listed above
if ($Index !== false) // If contains the $UndefinedIndex
{
$errstrbkup = $errstr; // Saves $errstr to another variable before the $errstr is changes
$str = str_replace("Undefined index:", "", $errstrbkup); // replaces "Undefined Index:" with nothing
$errstr = "A Button Does not Seem To Be Handled Correctly! <br> <b>Button Name:</b> $str "; // Changes the $errstr to a new message
}
$UndefinedIndex = "Undefined variable:"; // String to search for
$Variable = strpos($errstr, $UndefinedIndex); // Searches $errstr for the String listed above
if ($Variable !== false) // If contains the $UndefinedIndex
{
$errstrbkup = $errstr; // Saves $errstr to another variable before the $errstr is changes
$str = str_replace("Undefined variable:", "", $errstrbkup); // replaces "Undefined Index:" with nothing
$errstr = "A Variable Does Not Seem To Be Handled. Check $str"; // Changes the $errstr to a new message
}
$ErrorFile = str_replace("/home/u394942373/public_html/", "", $error_file); // Removes the /var/www from showing in the error
// remove the full path up to the file root if detected
echo
"Opps, It Seems An error Has Been Encountered <br>
Technical Information Listed Below: <br>
<br><br><br>
<b>Error Message:</b> $errstr <br>
<b>File Causing Error:</b> $ErrorFile<br>
<b>Line:</b> $error_line <br>
A Member Of The Technical Department Has Been Notified And Will Fix This Error When Available.
";
die();
}
//set error handler
set_error_handler("Error_Handler");
The reason for this, is because my line manager wishes to have a custom error handler for certain types of error messages... Or for every new error thrown would we still have the be modifying the current error handler