[英]PHP error_reporting either on or off
我無法在短時間內關閉已棄用的警告。 它們來自一個我不得不工作一段時間的垃圾堆腳本,其中過度使用了preg_replace和/ e修飾符。 與其去修復所有執行此操作的位置,不如在我正在處理時關閉不建議使用的警告,這是一個更好的主意。
奇怪的是,該腳本開頭的error_reporting函數似乎僅具有“打開/關閉”效果。 也就是說,我可以使用error_reporting(0)
完全關閉報告功能,並且可以使用error_reporting(E_ALL)
類的功能將其全部打開。 但是,使用以下任何選項均無效。 我仍然可以在頁面頂部看到100多個不推薦使用的警告。
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(E_ALL & ~E_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
我已驗證我的php.ini文件設置為E_ALL & ~E_DEPRECATED)
(24575),並且它在phpinfo()中顯示為此類。 項目根目錄中的.htaccess文件為空。 我什至不知道為什么還要有一個。
PHP 5.5.9-1ubuntu4.4
有任何想法嗎?
我要說的是,可能包含的另一個頁面或腳本將error_reporting設置為另一個值。 您可以不帶參數調用error_reporting()
以獲取當前值。 將其設置為某種值,並在包含其他文件后檢查該值是否未更改。
error_reporting(E_ALL | E_STRICT);
只是說“嘿,記錄這些錯誤/警告/通知”
我認為您將需要-
ini_set('display_errors', '0');
試試看。
解決方案:
ini_set("display_errors",'off');
在您的php腳本中使用它。它將隱藏警告出現在您的頁面中。
Other interesting options for that function:
<?php
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// For PHP >=5.3 use: E_ALL & ~E_NOTICE
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.