Is there any way I can get all notices, warnings, errors etc that PHP encounters stored in an array?
I need this for a custom error logger and I want it to catch also errors in addition to exceptions, which I already did.
I managed to find something for the last error, but that's not enough: error_get_last
You will have to build a custom error handler: http://www.php.net/manual/en/function.set-error-handler.php
$_ERRORS = array();
function myErrorHandler($errno, $errstr, $errfile, $errline) {
global $_ERRORS;
$_ERRORS[] = array("errno" => $errno, "errstr" => $errstr, "errfile" => $errfile, "errline" => $errline);
}
set_error_handler("myErrorHandler");
You could set a custom error handler and then either use a static variable to collect all the errors or write them as they occur to some kind of persistent storage.
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