调用set_error_handler来定义处理错误的类方法

时间:2014-11-10 20:33:56

标签: php custom-error-handling

所以我已经通过stackoverflow一次或大约十亿次尝试找到我的问题的答案,但到目前为止我还没有成功。他是问题所在。我正在使用trigger_error调用错误处理类的方法。无论出于何种原因,错误触发而不调用我定义的函数。请帮忙。这是我的代码

class runtime_errors
{
    public function __construct()
    {
        //  Calling required files
        include_once(ROOT."/inc/php/pac/browser_detect.php");
        include_once(ROOT."/inc/php/func/display_as.php");

        //  Setting needed class functions
        $this->browser      =   new BrowserDetection();
        $this->display_as   =   new display_as();

        //  if available we're going to set the query string
        if(isset($_SERVER['QUERY_STRING']))
            $this->query_string = $_SERVER['QUERY_STRING'];
        else
            $this->query_string = NULL;


        //  Setting this class and function as the error_handler, the & is important
        set_error_handler(array(&$this, 'log_error'));
    }

    public function log_error($errno, $errstr, $errfile, $errline)
    {
        echo 'am i working?';
    }
}

0 个答案:

没有答案