我一直在試圖編寫一個類來顯示錯誤和錯誤日誌。自定義類不顯示回顯
class CError {
//Error Logging
var $Log;
public function Log($Comment, $Detail = ""){
$Log .= $Comment . "\n";
if ($Detail !== ""){
$Log .= "--" . $Detail . "--\n";
}
}
public function Clear_Log(){
$Log = "";
}
public function Display_Log(){
echo $this->Log;
}
//Error Display
var $ErrorCode = array(
0 => "0: No Error Code found, so either you got here by some rogue code or ...",
1 => "1: General Error, if you are here something went wrong",
2 => "2: Invalid information provided",
3 => "3: Alternate path taken, check message for details",
42 => "42: Here is your answer, but do you know the question?",
50 => "50: You messed with the Creepers without your Diamond Sword, didn't you",
9001 => "9001: Its over 9000... or more likely a value used was to large",
418 => "418: I'm a Teapot, found the error that drove you crazy"
);
public function Error($Error = 0, $ShowLog = false){
if ($Error === ""){
$Error = 0;
}
foreach ($ErrorCode as $key => $value){
if($key == $Error){
echo "<h3 style='color:red'>" . $value . "</h3><br />";
}
}
if($ShowLog == true){
echo $this->Log;
}
}
}
這是我如何使用錯誤類
include 'CError.php';
$Error = new CError;
$Error->Log("Email is Required");
$Error->Display_Log();
$Error->Error(2,true);
是,使用時,顯示的問題罷了。它被跳過我認爲但不確定。我無法訪問服務器的錯誤日誌,因此我不知道是否正在生成錯誤,但代碼將貫穿到我主代碼中的退出點(與課程無關)
- -EDIT--
用$ this-> Log更改$ Log的答案已經解決了$ Log變量的問題。它仍然沒有解決在foreach循環中顯示錯誤代碼數組的問題。
- 編輯 -
我加入這個 - $>錯誤代碼的foreach循環解決的問題。
您正在爲此寫什麼PHP版本? – PeeHaa
@RepWhoringPeeHaa:我不確定確切的版本,但它是PHP 5.服務器由netfirms.ca在Linux上使用Apache(不確定味道) – RMDan
爲什麼使用'var'關鍵字? – PeeHaa