I already set my error handler:
set_error_handler (function($errno, $errstr, $errfile, $errline, array $errcontext) {
$s = date('Ymd_His');
switch ($errno)
{
case E_USER_ERROR:
$s.= '_E_';
break;
case E_USER_WARNING:
$s.= '_W_';
break;
case E_USER_NOTICE:
$s.= '_N_';
break;
default:
$s.= '_U_';
break;
}
file_put_contents (APP_PATH_CACHE.'/log'.$s.'_'.rand(1,99999).'.html', print_r(get_defined_vars(), true));
}, E_ALL);
but can it be turn into an exception? So that I could see the flow.
Converting errors into exception is done by calling set_error_handler() and throw new ErrorException() in there...
Remember, the PHP ini configuration has an error_reporting directive that will be set by this function during runtime. error_reporting(0); To remove all errors, warnings, parse messages, and notices, the parameter that should be passed to the error_reporting function is zero.
By default, PHP sends an error log to the server's logging system or a file, depending on how the error_log configuration is set in the php. ini file. By using the error_log() function you can send error logs to a specified file or a remote destination.
Yes, it is possible. This question speaks to the more general issue of how to handle errors in PHP.
Yes. this is exactly why the ErrorException was created. see http://php.net/manual/en/class.errorexception.php
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
set_error_handler("exception_error_handler");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With