<?php
//error handler function
function customError($errno, $errstr, $errfile, $errline, $errcontext) {
// If connection to the server is impossible
if ($errno == '2') {
echo "<p class='error'>Can not connect to the Database!</p>";
} else { // If some other error occurs
echo "<p class='error'>An error has occurred.</p><p>[".$errno ."] - ".$errstr ."</p>";
}
}
//set error handler
set_error_handler("customError");
?>
Basically it checks the error, if it's error number 2 (can't connect to the MySQL database), it shows "Can not Connect to the database". In all other cases it should show "An error has occurred". This works for most errors. But for some reason it doesn't work for Parse Errors. I trigger such an error by not ending a statement with a semicolon:
echo $myvariable
Instead of showing the text "An Error has occurred", it shows a 'normal' PHP error message:
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in error.php on line 66
Is there a way to also intercept Parse Errors?


Sign In
Create Account


Back to top









