I'm tring to set up my own custom error handling, but it's not working - I still get the default PHP errors, why is this?
index.php:
Code: Select all
<?php
// ------------- ~ Tango ~ ------------- \\
// File: index.php
// Author: Alex Cartwright
// Created: 12th November 2006
// ------------- ~ Tango ~ ------------- \\
// Include lib files
require_once( 'lib/libgeneral.php' );
// Include required core files
require_once( 'core/libehc.php' );
$libehc = new libehc();
woahError();
?>Code: Select all
<?php
// ------------- ~ Tango ~ ------------- \\
// File: core/libehc.php
// Author: Alex Cartwright
// Created: 20th November 2006
// ------------- ~ Tango ~ ------------- \\
// Set Error reporting level
error_reporting( E_ALL );
class libehc {
var $tangoErrors = NULL;
function libehc() {
// Take over from PHP's default error handling
set_error_handler( array( $this, 'errorHandler' ) );
}
//---
// errorHandler() is the main TangoCMS Error Handler
//---
function errorHandler( $type, $string, $file, $line, $vars ) {
// Decide what type of error has occured and handel it accordingly
switch( $type ) {
case E_TANGO:
$this->tangoError( $string, $file, $line, $vars );
break;
case E_USER_NOTICE:
case E_NOTICE:
$this->errorNotice( $string, $file, $line, $vars );
break;
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_CORE_WARNING:
case E_WARNING:
$this->errorWarning( $string, $file, $line, $vars );
break;
case E_USER_ERROR:
case E_COMPILE_ERROR:
case E_CORE_ERROR:
case E_ERROR:
case E_PARSE:
default:
$this->errorFatal( $string, $file, $line, $vars );
break;
}
}
//---
// tangoError() will store errors into an array
//---
function tangoError( $string, $file, $line, $vars ) {
$this->tangoErrors[] = $string;
}
//---
// errorFatal() will display a nice W3C page with a detailed error report then halt the script
//---
function errorFatal( $string, $file, $line, $vars ) {
$siteName = isDefined( "_CONFIG_TITLE", 'TangoCMS' );
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>'.$siteName.' - Error</title>
</head>
<body>
<strong>A severe error has occured and caused the page to halt:</strong><br />'.$string.'<br /><br />
<textarea cols="60" rows="10" readonly="readonly" name="error">'.
$string.', in '.$file.' on line '.$line.'
</textarea>
<br /><br />
Please refresh the page to try again. If the problem continues, we shall try to fix it as soon as possible. Thank you
</body>
</html>';
die();
}
//---
// errorWarning() will output a detailed error
//---
function errorWarning( $string, $file, $line, $vars ) {
echo '<strong>Warning:</strong>'.$string.', in '.$file.' on line '.$line;
}
//---
// errorNotice() will output a detailed error
//---
function errorNotice( $string, $file, $line, $vars ) {
echo '<strong>Notice:</strong>'.$string.', in '.$file.' on line '.$line;
}
}
?>