Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用set_error_handler定义类方法来处理错误_Php_Custom Error Handling - Fatal编程技术网

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

Php 调用set_error_handler定义类方法来处理错误,php,custom-error-handling,Php,Custom Error Handling,因此,我已经经历了一次或大约十亿次stackoverflow,试图找到问题的答案,但迄今为止我一直没有成功。他是问题所在。我正在使用trigger\u error调用一个错误处理类的方法。无论出于何种原因,错误都会在不调用我定义的函数的情况下触发。请帮忙。这是我的密码 class runtime_errors { public function __construct() { // Calling required files include_o

因此,我已经经历了一次或大约十亿次stackoverflow,试图找到问题的答案,但迄今为止我一直没有成功。他是问题所在。我正在使用trigger\u 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?';
    }
}

你是否正在创建类
运行时\u errors
的实例?我已将该类包含在另一个类的构造函数中,并几乎直接创建了错误处理程序类的实例。我明白了。您正在
构造函数中使用
$this
,但是
$this
仅在
构造函数完成工作时才会反映实例。你应该试着把这个调高。试试这个:在创建实例的另一个类中,这样做:`$o=newruntime_errors();设置错误处理程序($o,'log_error');如果可以的话,你可以在你的运行时错误类中使用一个静态函数来初始化一个实例并设置错误处理程序。我希望我清楚这一点:)我完全理解,幸运的是我不需要使用那种方法。在我回复之后,我又开始修改课程,并注意到了一些事情。(1) 我的错误处理程序类没有直接输出错误,而是将它们存储在类中,这样可以在不中断页面流的情况下显示它们。(2) 我在初始化错误处理类的新实例的类的构造函数中调用了该函数(display error函数)。这意味着在大多数情况下,我在创建错误消息之前请求错误消息。我移动了err_显示屏,使它沿着析构函数运行,一切似乎又开始工作了