bapi Posted May 30, 2007 Share Posted May 30, 2007 Hi, I am new to OOP. Can any one give / suggest me a ERROR HANDLER script and show me how to use it in other class. Pls. helllllllllllllllllllllllllllllllllllllllllp ! Quote Link to comment https://forums.phpfreaks.com/topic/53584-creating-oop-error-handler-class-and-its-use/ Share on other sites More sharing options...
Jenk Posted June 1, 2007 Share Posted June 1, 2007 You can "helllllllllllllllllllllllllllllllllllllllllp" us, by firstly removing whatever it is that is sticking your 'l' key down, then by posting any code you have already started with. Quote Link to comment https://forums.phpfreaks.com/topic/53584-creating-oop-error-handler-class-and-its-use/#findComment-266143 Share on other sites More sharing options...
jnewing Posted June 1, 2007 Share Posted June 1, 2007 Well for a simple example you could do something like this: <?php /** * All my Error defines */ // Few Options define('DISPLAY_ERROR', true); define('LOG_ERROR', true); define('LOG_DB_TABLE', 'error_logs'); // Database Error Messages define('E_DB_CONN', 'Error connecting to the database'); define('E_DB_QUERY', 'There was an error in the query'); // User Login Error Messages define('E_USER_LOGIN', 'You have entered and invalid username or password'); define('E_USER_TIMEOUT', 'Your session has expired, please login again'); // Define my custom error levels define(-1, 'E_DB'); define(-2, 'E_USER'); // etc... class ErrorMsg { protected $_EMSG = NULL; protected $_ETYPE = NULL; function __contrcut($errorID = 0, $errorMSG = '') { switch ($errorID) { case -1: $this->_ETYPE = 'Database Error: '; $this->_EMSG = $errorMSG; break; case -2: $this->_ETYPE = 'User Error: '; $this->_EMSG = $errorMSG; break; // etc... default: //unknow or unaccounted for error $this->_ETYPE = 'Unknown Error: '; $this->_EMSG = 'An unknown error occured.'; break; } if (LOG_ERROR) { ErrorMsg::logError(); } if (DISPLAY_ERROR) { ErrorMsg::displayError(); } } function logError() { // DB Connection stuff // Exe the DB query $db->query("insert into " . LOG_DB_TABLE . " (error_id, error_message, error_time) VALUES ('$this->_ETYPE', '$this->_EMSG', NOW())"); return true; } function displayError() { print "<strong>$this->_ETYPE</strong>: $this->_EMSG"; return true; } } ?> Please keep in mind this is just an example i just slapped down in a few mins right in this editor, so sorry if the spacing is off etc.. and you would have to really tweek it to get it to work for you but it's an idea anyways, hopefully it will lead you down the right path. Quote Link to comment https://forums.phpfreaks.com/topic/53584-creating-oop-error-handler-class-and-its-use/#findComment-266298 Share on other sites More sharing options...
obsidian Posted June 1, 2007 Share Posted June 1, 2007 Hi, I am new to OOP. Can any one give / suggest me a ERROR HANDLER script and show me how to use it in other class. Pls. helllllllllllllllllllllllllllllllllllllllllp ! Are you referring to ERRORS or actually handling Exceptions? The latter was introduced with PHP5 and is what most people are working with when it comes to OOP. A little further explanation of what you need would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/53584-creating-oop-error-handler-class-and-its-use/#findComment-266309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.