Skip to content

Instantly share code, notes, and snippets.

@gcatlin
Created May 30, 2013 13:53
Show Gist options
  • Save gcatlin/5677984 to your computer and use it in GitHub Desktop.
Save gcatlin/5677984 to your computer and use it in GitHub Desktop.
Adds support for multiple error handlers in PHP
<?php
function append_error_handler($handler) {
set_error_handlers(array(set_error_handler($handler), $handler));
}
function prepend_error_handler($handler) {
set_error_handlers(array($handler, set_error_handler($handler)));
}
function set_error_handlers($handlers) {
$handlers = (is_array($handlers) ? $handlers : array($handlers));
set_error_handler(function ($level, $message, $file = null, $line = null, $context = null) use ($handlers) {
foreach ($handlers as $handler) {
if ($handler) {
call_user_func($handler, $level, $message, $file, $line, $context);
}
}
});
}
@gcd2510
Copy link

gcd2510 commented Feb 20, 2017

Can you explain a little bit about 3 function??. i cant understand what they do. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment