Skip to content

Instantly share code, notes, and snippets.

@lastguest
Created January 30, 2013 11:26
Show Gist options
  • Save lastguest/4672628 to your computer and use it in GitHub Desktop.
Save lastguest/4672628 to your computer and use it in GitHub Desktop.
Chain-in a new PHP error_handler not destroying the old one.
<?php
set_error_handler(function(){ echo "INTERNAL\n"; });
function chain_error_handler($new_handler){
$old_handler = set_error_handler(function() use (&$old_handler,$new_handler){
call_user_func_array($new_handler,func_get_args());
call_user_func_array($old_handler,func_get_args());
});
}
chain_error_handler(function(){ echo ":D\n"; });
$a = 1/0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment