I am trying to add some error handling to my code.  Instead of
reinventing the wheel, I searched and found the code below.  For the
most part, it seems to work.  When I have an error, it doesn't get
shown.  However, I don't get any output.  I tracked it down to the
$errno.  It is outputting a number where the switch statement is
expecting words.   Short of typing an array converting number to
words, what am I missing/doing wrong?

set_error_handler('errorHandler');

function errorHandler ($errno, $errstr, $errfile, $errline, $errcontext){
        global $query;

        switch ($errno){
                case E_USER_WARNING:
                case E_USER_NOTICE:
                case E_WARNING:
                case E_NOTICE:
                case E_CORE_WARNING:
                case E_COMPILE_WARNING:
                        break;
                case E_USER_ERROR:
                case E_ERROR:
                case E_PARSE:
                case E_CORE_ERROR:
                case E_COMPILE_ERROR:

                if(eregi('^(sql)$', $errstr)){
                        $MYSQL_ERRNO = mysql_errno();
                        $MYSQL_ERROR = mysql_error();
                        $errstr = "MySQL error: $MYSQL_ERRNO : $MYSQL_ERROR";
                }else{
                        $query = NULL;
                }
                
                $errorstring = "<h2>" .date('Y-m-d H:i:s') ."</h2>\n";
                $errorstring .= "<p>Fatal Error: $errstr (# $errno).</p>\n";
                
                if ($query) $errorstring .= "<p>SQL query: $query</p>\n";
                
                $errorstring .= "<p>Error in line $errline of file 
'$errfile'.</p>\n";
                $errorstring .= "<p>Script: '{$_SERVER['PHP_SELF']}'.</p>\n";
                
                if(isset($errcontext['this'])){
                        if(is_object($errcontext['this'])){
                                $classname = get_class($errcontext['this']);
                                $parentclass = 
get_parent_class($errcontext['this']);
                                $errorstring .= "<p>Object/Class: '$classname', 
Parent Class:
'$parentclass'.</p>\n";
                        }
                }
                
                echo "<h2>This system is temporarily unavailable</h2>\n";
                echo "<p>The following has been reported to the 
administrator:</p>\n";
                echo "<b><font color='red'>\n$errorstring\n</b></font>";
                
                /*error_log($errorstring, 1, $_SERVER['SERVER_ADMIN']);
                
                $logfile = $_SERVER['DOCUMENT_ROOT'] .'/errorlog.html';
                error_log($errorstring, 3, $logfile);*/
                
                /*session_start();
                session_unset();
                session_destroy();*/
                
                die();
                default:
                break;
                }


        # prevent further script execution
        exit();
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to