PHP報錯層級設定和原理分析

來源:互聯網
上載者:User

這篇文章主要介紹了關於PHP報錯層級設定和原理分析 ,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

原理簡介

在PHP設定檔中php.ini有如下配置:

; Error Level Constants:; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0); E_ERROR           - fatal run-time errors; E_RECOVERABLE_ERROR  - almost fatal run-time errors; E_WARNING         - run-time warnings (non-fatal errors); E_PARSE           - compile-time parse errors; E_NOTICE          - run-time notices (these are warnings which often result;                     from a bug in your code, but it's possible that it was;                     intentional (e.g., using an uninitialized variable and;                     relying on the fact it is automatically initialized to an;                     empty string); E_STRICT          - run-time notices, enable to have PHP suggest changes;                     to your code which will ensure the best interoperability;                     and forward compatibility of your code; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's;                     initial startup; E_COMPILE_ERROR   - fatal compile-time errors; E_COMPILE_WARNING - compile-time warnings (non-fatal errors); E_USER_ERROR      - user-generated error message; E_USER_WARNING    - user-generated warning message; E_USER_NOTICE     - user-generated notice message; E_DEPRECATED      - warn about code that will not work in future versions;                     of PHP; E_USER_DEPRECATED - user-generated deprecation warnings;; Common Values:;   E_ALL (Show all errors, warnings and notices including coding standards.);   E_ALL & ~E_NOTICE  (Show all errors, except for notices);   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.);   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors); Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED; Development Value: E_ALL; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT; http://php.net/error-reportingerror_reporting = E_ALL

上面配置中:error_reporting為設定配置層級;預設是E_ALL,意思顯示所有Notice,Warning,Error資訊(Show all errors, warnings and notices including coding standards.)。
在PHP手冊預定義常量中有詳細解釋,下面為摘錄的一部分:

例子:E_ALL & ~E_NOTICE
E_ALL: 111011111111111
E_NOTICE: 1000
~E_NOTICE: 0111
E_ALL & ~E_NOTICE:111011111110111

php就是這樣通過二進位的轉換來控制錯誤層級的。

調整錯誤層級

全域設定

更改php.ini檔案中的error_reporting就可以達到效果。
例如:

1. error_reporting = E_ALL #輸出所有錯誤,警告,notice資訊2. error_reporting = E_ALL & ~E_NOTICE #輸出所有錯誤和警告資訊,不輸出notice資訊3. E_ALL & ~E_NOTICE & ~E_WARNING #輸出所有錯誤資訊,不輸出警告,notice資訊

局部設定

在指令碼或程式中,通過ini_set()和error_reporting()設定可以達到效果。
例如:

ini_set("display_errors",1)error_reporting(E_ALL)

相關推薦:

PHP報錯並自動跳轉

開發模式與產品模式下的PHP報錯處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.