整合環境預設 error_reporting = E_ALL,頁面頂部出現大量 Notice: Undefined variable、Notice: Undefined index 等提示,影響觀感與效能。
php.ini(WAMP 典型路徑:D:\wamp\bin\php\php5.3.10\php.ini)。error_reporting。; 修改前
error_reporting = E_ALL
; 修改後(推薦)
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; 或僅排除 Notice
error_reporting = E_ALL & ~E_NOTICE
E_ALL 包含所有錯誤等級。~E_NOTICE 以位運算排除 Notice(值 8)。E_STRICT (2048)、E_DEPRECATED (8192)。<?php
// 僅影響當前腳本
error_reporting(E_ALL & ~E_NOTICE);
// 或運行時開啟/關閉
ini_set('error_reporting', E_ALL & ~E_NOTICE);
| 環境 | error_reporting | display_errors | log_errors |
|---|---|---|---|
| 開發 | E_ALL | On | On |
| 測試/預發 | E_ALL & ~E_NOTICE | Off | On |
| 生產 | E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED | Off | On |