2011-11-15 25 views
1

我試圖禁用的文件錯誤的顯示和只要登錄他們到一個日誌文件如何禁用PHP錯誤顯示的,並在文件中記錄他們

<?php 
error_reporting('E_ALL'); 
echo $x; 
?> 

日誌文件的工作時,我刪除error_reporting('E_ALL'),但也會顯示錯誤。 是否有另一種方法來執行此操作,但僅在特定頁面上禁用錯誤報告。

回答

3

您可以通過set_error_handler()創建一個自定義的錯誤處理功能並進行設置:

set_error_handler(function($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null) 
{ 
    // Append $errstr and other useful information to a file 
    @file_put_contents('error_log', "ERROR: $errstr\n", FILE_APPEND); 

    return true; // disable regular PHP error reporting 
}); 
相關問題