How to see php errors in firebug

Tagged:  

If you want to see php errors in firebug here is how you do it: <?php
 
/**
* class: Debugger
* author: <a href="http://doru.serveblog.net">Moisa Doru</a>
* contact: <a href="mailto:moisadoru@gmail.com">moisadoru@gmail.com</a>
* info: this class displays PHP errors in Firebug; works only in PHP5, tested in PHP 5.2.0
* usage: <strong>include_once("debugger.php")</strong> as the very first include();
* licence: free as in free beer ;)
*/
 
class Debugger {
private static $instance;
private $messages = array();
 
private function __construct(){
ob_start();
}
 
public static function create(){
if (!isset(self::$instance)) self::$instance = new Debugger;
return self::$instance;
}
 
public function __clone(){
$this->error('Clone of Debugger is not allowed.');
}
 
public function error($msg){
$this->messages[] = 'console.error('.$msg.');';
}
 
public function flushData(){
echo '<script type="text/javascript">'.
"\n".'//<![CDATA['.
"\n if(typeof console == 'undefined' || typeof window.console == 'undefined') {".
" var go = confirm('The PHP Debugger class needs Firebug to be installed.".
"\\nDo you want to install it now ?'); ".
" if(go) window.location='http://getfirebug.com'; }".
" else {".
'console.warn("PHP Errors:");'."\n";
foreach($this->messages as $k=>$v) echo $v."\n";
echo "\n}\n".'//]]>'."\n".'</script>'."\n";
}
public function capture($errno, $errstr, $errfile, $errline, $errcontext){
$errstr = str_replace('"','\\"',$errstr);
$errfile = str_replace('\\','\\\\',$errfile);
$this->error('"PHP Error ('.$errno.'): '.$errstr.', in '.$errfile.' at line: '.$errline.'"');
}
public function __destruct(){
ob_end_flush(); }
};
$DBG = Debugger::create();$oldErrHandler = set_error_handler(array(&$DBG, 'capture'), 2047 );register_shutdown_function(array(&$DBG,'flushData'));// test//$x = $y;
?>