【发布时间】: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