SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    New York
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why does this error handler not work?

    Hi, I have this error handler which doesn't work correctly. It seems as if it's not setting variables. Probably a problem with a static function requirement? Anyway, I'm wondering if one of you guys can get it to work? I'm hoping it's an easy fix. Here's the code: (avoid the trigger object stuff... not important)

    main handler:
    PHP Code:
    require_once('dotarch.error.php');
    require_once(
    'dotarch.trigger.php');

    class 
    errorhandler
    {
        var 
    $handler;
        var 
    $errObj;
        var 
    $trigObj;
        var 
    $debug;

        function 
    errorhandler($conn false$debug true) {
            
    $this->debug $debug;
            
    $this->errObj  = new error($conn$debug);
            
    $this->trigObj = new trigger($conn);
            
    $this->reset();
        }
        function 
    getErrorInstance() {
            return 
    $this->errorObj;
        }
        function 
    getMessageInstance() {
            return 
    $this->trigObj;
        }
        function 
    restore() {
            
    restore_error_handler();
        }
        function 
    reset() {
            
    set_error_handler(array(&$this'_handler'));
        }
        function 
    _handler($type$msg$file$line) {
            if(
    $type error_reporting() == 0) {
                return;
            }
            if(
    $this->debug) {
                
    $this->debug false;
                
    ob_start();
            }

            
    $user_errors = array(E_USER_ERRORE_USER_WARNINGE_USER_NOTICE);

            if(
    in_array($type$user_errors)) {
                
    $extract explode('|'$msg);
                
    $this->trigObj->set($extract[0], $extract[1]);
            } else {
                
    $this->errObj->set($type$msg$file$line);
            }
        }

    error class:
    PHP Code:
    class error
    {
        var 
    $connection;
        var 
    $can_log;
        var 
    $error;
        var 
    $debug;
        
        function 
    error($conn false$debug true) {
            if(
    $conn) {
                
    $this->connection $conn;
                
    $this->can_log true;
            } else {
                
    $this->can_log false;
            }
            
            
    $this->debug $debug;
            
    $this->error = array();
        }
        function 
    set($type$msg$file$line) {
            
    $this->error[$type]['msg']  = $msg;
            
    $this->error[$type]['file'] = $file;
            
    $this->error[$type]['line'] = $line;
            
            switch(
    $type) {
                case 
    E_ERROR:
                    
    $this->log('E_ERROR');
                    
    $this->display('E_ERROR');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_WARNING:
                    
    $this->log('E_WARNING');
                    
    $this->display('E_WARNING');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_NOTICE:
                    
    $this->log('E_NOTICE');
                    
    $this->display('E_NOTICE');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_PARSE:
                    
    $this->log('E_PARSE');
                    
    $this->display('E_PARSE');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_CORE_ERROR:
                    
    $this->log('E_CORE_ERROR');
                    
    $this->display('E_CORE_ERROR');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_CORE_WARNING:
                    
    $this->log('E_CORE_WARNING');
                    
    $this->display('E_CORE_WARNING');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_COMPILE_ERROR:
                    
    $this->log('E_COMPILE_ERROR');
                    
    $this->display('E_COMPILE_ERROR');
                    unset(
    $this->error[$type]);
                    break;
                case 
    E_COMPILE_WARNING:
                    
    $this->log('E_COMPILE_WARNING');
                    
    $this->display('E_COMPILE_WARNING');
                    unset(
    $this->error[$type]);
            }
        }
        function 
    log($type NULL) {
            if(!
    $this->can_log) return;
            if(!isset(
    $type)) return;
            
            
    $msg  $this->error[$type]['msg'];
            
    $file $this->error[$type]['file'];
            
    $line $this->error[$type]['line'];

            
    $this->connection->query('INSERT INTO errors (errtype, errline, errfile, error) VALUES ('."'$type',$line,'$file','$msg'".')'false);
        }
        function 
    display($type NULL) {
            if(!isset(
    $type)) return;
            if(
    $this->debug) {
                while(
    ob_get_level() !== 0) {
                    
    ob_end_clean();
                }
            }
            
            
    $this->_display($type$this->error[$type]['msg'], $this->error[$type]['file'], $this->error[$type]['line']);
            
            if(
    $this->debug) {
                
    ob_start();
            }
        }
        function 
    _display($type$msg$file$line) {
            echo 
    '<strong><font face="verdana, arial" size="4" color="red">' $type '</font></strong>';
            echo 
    '<hr style="margin:0;padding:0" />';
            echo 
    '<strong><font face="verdana, arial" size="2">DEBUG INFORMATION:</font></strong><br />';
            echo 
    '<font face="verdana, arial" size="2"><strong>Error: </strong>' htmlspecialchars($msg) . '</font><br />';
            echo 
    '<font face="verdana, arial" size="2"><strong>File: </strong>' htmlspecialchars($file) . '</font><br />';
            echo 
    '<font face="verdana, arial" size="2"><strong>Line: </strong>' htmlspecialchars($line) . '</font><br />';
            echo 
    '<hr /><br />';
        }

    viveHosting.com
    Affordable Hosting, Reliable Service

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    New York
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    someone please help?
    viveHosting.com
    Affordable Hosting, Reliable Service

  3. #3
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Custom error handlers cannot catch E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and E_STRICT errors.
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    New York
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't have those on until someone said what was on the manual was only pertaining to handling context. But I'll trust you know better. But that's not the reason the script isn't working, so have any thoughts?
    viveHosting.com
    Affordable Hosting, Reliable Service


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •