DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
PHP Error Listener
Error listener for PHP, shows simple errors as exceptions.
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
class ErrorListener{
static protected $listening = false;
static protected $listeningExceptions = false;
public static function start(){
if(self::$listening)
return;
set_error_handler(array('ErrorListener', 'dispatcher'));
self::$listening = true;
}
public static function stop(){
if(!self::$listening)
return;
restore_error_handler();
self::$listening = false;
}
public static function dispatcher($code, $message){
throw new Exception($message, $code);
}
public static function setDefaultExceptionHandler($callback){
if(self::$listeningExceptions)
return;
set_exception_handler($callback);
}
public static function restoreDefaultExceptionHandler(){
if(!self::$listeningExceptions)
return;
restore_exception_handler();
}
}




