【问题标题】:PHP set_error_handler all projectPHP set_error_handler 所有项目
【发布时间】:2015-12-13 13:51:08
【问题描述】:

我有一个有个人句柄错误的类,所以我想将此功能设置为我的所有项目。我怎样才能做到这一点?这是一个好方法吗?

我的班级:

<?php 

define("LOG_FILE", "/tmp/errors.log");

class ErrorManager{


function handleError($error_number, $error_messsage, $error_file){
        ini_set("log_errors", 1);
        error_log( "Some Error message!", 3, LOG_FILE);
        return true;
    }
}


?>

我这样称呼它:

function Connect() {
        $this->status = 0;
        $this->host = $_SESSION['dbhost'];
        $this->user = $_SESSION['dbuser'];
        $this->pass = $_SESSION['dbpassword'];
        $this->dbname = $_SESSION['dbnamebase'];
        $this->db = mysqli_connect($this->host, $this->user, $this->pass);

        $old_error_handler = set_error_handler('ErrorManager::handleError', E_ALL);

        if (!$this->db) {
            trigger_error("errou feio", E_USER_ERROR);
        } else {
            $this->status = 1;
            mysqli_select_db($this->db,$this->dbname);
        }
    }

【问题讨论】:

    标签: php error-handling error-log


    【解决方案1】:

    看起来您将错误处理程序初始化放在了数据库连接类中。如果您希望您的错误处理程序尽可能早地随处可用,您应该将它放在作为应用程序入口点的任何文件中(index.php、app.php...)。这样,您就可以确定它始终处于活动状态并从一开始就启用。

    【讨论】:

      【解决方案2】:

      正如this.lau_所说:你应该把它放在任何文件中作为你的应用程序的入口点(index.php,app.php...)。这样,您就可以确定它始终处于活动状态并从一开始就启用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-01
        • 2011-09-07
        • 1970-01-01
        • 1970-01-01
        • 2017-04-16
        • 2020-09-29
        相关资源
        最近更新 更多