Hi i'm currently making a highly modular forum in PHP and i'm running into a slight problem with an error handler that i have started on and it has been stumping me, any help would be very much appreciated.
Auzzie 6 Junior Poster
<?php
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Acid Avengers Software +++
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Product: Acid RPG +++
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Website: http://www.acidavengers.co.uk +++
+++ E-Mail: support@acidavengers.co.uk +++
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Created By: Marc "Acid Burn" Towler +++
+++ Copyright 2006 - 2007 Acid Avengers +++
+++++++++++++++++++++++++++++++++++++++++++++++++++
+++ File Name: error.engine.php +++
+++ File Version: 0.1 +++
+++++++++++++++++++++++++++++++++++++++++++++++++++
*/
//The Exception Class/*
class Exception {
function __construct(string $message=NULL, int $code=0) {
if(func_num_args()) {
$this->message = $message;
}
$this->code = $code;
$this->file = __FILE__; //Of throw clause
$this->line = __LINE__; //of throw clause
$this->trace = debug_backtrace();
$this->string = StringFormat($this);
}
protected $message = 'Unknown Exception'; //Exception message
protected $code = 0; //User defined exception code
protected $file; //Source filename of exception
protected $line; //Source line of exception
private $trace; //Backtrace of exception
private $string; //Internal only!!
final function getMessage() {
return $this->message;
}
final function getCode() {
return $this->code;
}
final function getFile() {
return $this->file;
}
final function getTrace() {
return $this->trace;
}
final function getTraceAsString() {
return self::TraceFormat($this);
}
function _toString() {
return $this->string;
}
static private function StringFormat(Exception $exception) {
//... a function not available in PHP scripts
//that returns all relevant information as a string
}
static private function TraceFormat(Exception $exception) {
//... a function not available in PHP scripts
//that returns the backtrace as a string
}
}*/
//We need base classes for files and databases that extends Exception,
//It also needs to be extendable for seperate classes
class ErrorHandler {
//Covers for default error handler under it's format:
// function(int error_type, string error_msg [, string errfile
// [, int errline [, array errcontext]]])
function __construct(int $Num = 0, string $error = NULL, string $file, int $line = 0) {
if($num != 0) {
$this->message = $message;
}
$this->code = $Num;
$this->message = $error;
$this->file = $file;
$this->line = $line;
}
protected $error = 'Unknown Error'; //Here is the error message
protected $Num = 0; //Here is the error code
protected $file; //Here is the problem file
protected $line = 0; //Here is the error line
function ErrorMessage() {
return $this->message;
}
function ErrorCode() {
return $this->code;
}
function ErrorFile() {
return $this->file;
}
function ErrorLine() {
return $this->line;
}
}
//File error handler, extended from ErrorHandler class
class FileError extends ErrorHandler {
//Start the Logger engine
$Logger = new LogFileEngine;
/*********************************************************************
*** Function: WriteOutput ***
*** Desc: Writes a friendly error to the screen and logs the error ***
*********************************************************************/
function WriteOutput() {
$output = '<br /><table bgcolor="#CCCCCC"><tr><td>";
$output .= '<p style="color: #FF0000;"><strong>File Error:</strong> '. $this->ErrorMessage() .'</p>';
//Check to see what type of error it was
switch($this->code) {
case 1, 256:
$output .= '<br /><p>This was a fatal error, it has been reported to the staff</p>';
$output .= '<p>We apologise for the inconveniance caused.</p>';
break;
case 2, 512: //This is a warning, not an error, only visible in debug mode so show full details
$output .= '<br /><p>A warning has been issued in '. $this->ErrorFile() .' on line '. $this->line();
$output .= '</p><p>Although it is only a warning, it could be a security hole.</p>';
break;
case 4: //This is parse errors, just as bad as a fatal error
$output .= '<br /><p>There was a parse error in '. $this->file() .'. It has been reported to the staff</p>';
$output .= '<p>We apologise for the inconveniance caused.</p>';
break;
case 8, 1024: //This is a notice level warning, only visible in debug mode so show full details
$output .= '<br /><p>A notice has been issued in '. $this->ErrorFile() .' on line '. $this->line();
$output .= '</p><p>This is a security level fix so it has been added to the job list.</p>';
break;
}
//Finish off the error message and then write to the log file
$output .= '</td></tr><table>';
$Logger->FileError($output);
//Return the message to the user
return $output;
}
}
//Database error handler, extended from ErrorHandler class
class DatabaseError extends ErrorHandler {
//Start the Logger engine
$Logger = new LogFileEngine;
function DBError() {
//Check to see what the error actually is
switch($this->code) {
}
}
}
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster
1. Line 74. You are ending a comment */. It doesn't have a matching /* .
2.
function WriteOutput() {
$output = '<br /><table bgcolor="#CCCCCC"><tr><td>";
You are assigning a string to $output. It starts with a ' but ends with a ".
3. I am not sure if your switch case will work. I usually use
switch($value) {
case 1:
case 3:
echo "Odd number";
break;
case 2:
case 4:
echo "even number";
break;
I m not sure about case 1,256:
Umm.. These are the few errors that I see.
Cheers,
Naveen
Auzzie 6 Junior Poster
simple, simple errors :( but the main one is php is telling me i am reassigning $this
nav33n 472 Purple hazed! Team Colleague Featured Poster
I dunno! never heard of that before..
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.