When my script starts, I have:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
And then, I register my custom error handler with PHP:
function handleError($code, $text, $file, $line) {
echo "&%!!";
return true;
}
set_error_handler('handleError');
Next, there comes some code that produces an error like this:
Fatal error: Call to undefined method
DB::getInstanceForDB() in
/Applications/MAMP/htdocs/mysite/classes/Test.php
on line 32
I keep getting the standard PHP error message box with call stack and everything on my site, no matter if I specify a custom error handler or not. Any idea what’s wrong?
Edit: No matter if I return true or not, it doesn’t call my custom handler.
First, you need to make your error handling function return true. From set_error_handler:
Second, be aware that fatal errors aren’t handled by
set_error_handler. You need to use register_shutdown_function as well. So your code should look like this: