I am trying to follow a script for creating my own error handler however I am expecting "A system error occurred. We apologise for the inconvenience." instead I get the following, why am I getting a fatal error surely it should just be another "A system error occurred. We apologise for the inconvenience." message ?
A system error occurred. We apologise for the inconvenience.
A system error occurred. We apologise for the inconvenience.
Fatal error: Uncaught DivisionByZeroError: Division by zero in /var/ Stack trace: #0 {main} thrown in /var/ on line 29
I am using php 8.1.14, the example in the book originally had 5 values for my_error_handler however I see that in php 8 it has been reduced to 4. Any help appreciated, thank you
<?php
define('LIVE',TRUE);
$e_vars = 'ok';
// create the error handler
function my_error_handler($e_number,$e_message,$e_file,$e_line) {
// build the message
$message ="An error occurred in script '$e_file' on line $e_line : $e_message\n";
// append $e_vars to $message
$message .= print_r($e_message,1);
if(!LIVE){
echo '<pre>'.$message."\n";
debug_print_backtrace();
echo '</pre><br />';
} else {
echo '<div class="error">A system error occurred. We apologise for the inconvenience.</div><br />';
}
}
set_error_handler('my_error_handler');
// create errors
foreach ($vars as $v){}
$result = 1/0;
?>
A system error occurred. We apologise for the inconvenience.
A system error occurred. We apologise for the inconvenience.
Fatal error: Uncaught DivisionByZeroError: Division by zero in /var/ Stack trace: #0 {main} thrown in /var/ on line 29
I am using php 8.1.14, the example in the book originally had 5 values for my_error_handler however I see that in php 8 it has been reduced to 4. Any help appreciated, thank you
<?php
define('LIVE',TRUE);
$e_vars = 'ok';
// create the error handler
function my_error_handler($e_number,$e_message,$e_file,$e_line) {
// build the message
$message ="An error occurred in script '$e_file' on line $e_line : $e_message\n";
// append $e_vars to $message
$message .= print_r($e_message,1);
if(!LIVE){
echo '<pre>'.$message."\n";
debug_print_backtrace();
echo '</pre><br />';
} else {
echo '<div class="error">A system error occurred. We apologise for the inconvenience.</div><br />';
}
}
set_error_handler('my_error_handler');
// create errors
foreach ($vars as $v){}
$result = 1/0;
?>