Let's suppose I have this piece of code, where I try to make sure all my errors are reported in some way, yet the visitors won't have to see but a nice page apologizing for the situation.
ini_set('display_errors', 'off');
error_reporting(E_ALL);
set_exception_handler('exceptionHandler');
function exceptionHandler($error)
{
// functionWithSyntaxError()
undefinedFunction();
echo $error->getMessage();
}
If I would have functionWithSyntaxError()
uncommented, I would see the error about the syntax. I guess that's because the code is not even run and the compiler doesn't care about my exception handler or other directives.
Now, if I comment it back and leave only undefinedFunction()
, I wouldn't be able to log the error about the undefined function, either would my code run further. I wouldn't know what happens so I would have to set display_errors
ON, in which case I would defy my original purpose of not displaying errors, but reporting them silently.
So, in this case I guess the compiler doesn't check for undefined function as it does with the syntax. What happens in this case? It certainly doesn't continue either. Shouldn't the code go in a loop? What happens under the hood?
I know I have better options to handle errors gracefully, defining a debug mode (where errors will be displayed), for example, but I just want to understand the intricacies of this situation