首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

WAMP / XAMPP / AppServ 關閉 PHP Notice 警告的統一方法

     編輯:PHP 綜合知識

現象

整合環境預設 error_reporting = E_ALL,頁面頂部出現大量 Notice: Undefined variable、Notice: Undefined index 等提示,影響觀感與效能。

修改 php.ini

  1. 定位 php.ini(WAMP 典型路徑:D:\wamp\bin\php\php5.3.10\php.ini)。
  2. 搜尋 error_reporting。
  3. 將預設值修改為排除 Notice:
; 修改前
error_reporting = E_ALL

; 修改後(推薦)
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

; 或僅排除 Notice
error_reporting = E_ALL & ~E_NOTICE

重啟生效

  • WAMP:左鍵圖示 → Restart All Services。
  • XAMPP:Control Panel → Stop/Start Apache。
  • AppServ:服務管理重啟 Apache。

原理說明

  • E_ALL 包含所有錯誤等級。
  • ~E_NOTICE 以位運算排除 Notice(值 8)。
  • 同理可排除 E_STRICT (2048)、E_DEPRECATED (8192)。

程式碼層面臨時覆蓋(不改 php.ini)

<?php
// 僅影響當前腳本
error_reporting(E_ALL & ~E_NOTICE);

// 或運行時開啟/關閉
ini_set('error_reporting', E_ALL & ~E_NOTICE);

生產環境建議

生產環境嚴禁 display_errors=On,錯誤應寫入日誌 (error_log) 供開發者分析。

總結

修改 php.ini 中 error_reporting = E_ALL & ~E_NOTICE 並重啟 Apache,即可在所有整合環境 (WAMP/XAMPP/AppServ) 統一關閉 Notice 警告。開發階段建議保留 E_ALL 以盡早發現潛在 Bug。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved
環境error_reportingdisplay_errorslog_errors
開發E_ALLOnOn
測試/預發E_ALL & ~E_NOTICEOffOn
生產E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATEDOffOn