PHP的error_reporting錯誤層級變數對照表,errorreporting
在PHP中所有的報錯資訊可以用error_reporting()這個函數來設定:
它的參數有字串和數字兩種表示方法,共14個等級,但是呢,我看使用其他數字貌似也可以,起初我以為它指的是一定的報錯區間,後來,終於發現了其中的規律:
複製代碼 代碼如下:error_reporting( 7 ) = error_reporting( 1+2+4)= error_reporting(E_ERROR | E_WARING | E_PARSE)
現在,我將其總結如下:
| 數字 |
常量 |
說明 |
| 1 |
E_ERROR |
致命錯誤,指令碼執行中斷,就是指令碼中有不可識別的東西出現 舉例: Error:Invalid parameters. Invalid parameter name |
| 2 |
E_WARNING |
部分代碼出錯,但不影響整體運行 舉例: Warning: require_once(E:/include/config_base.php) |
| 4 |
E_PARSE |
字元、變數或結束的地方寫規範有誤 舉例: Parse error: syntax error, unexpected $end in |
| 8 |
E_NOTICE |
一般通知,如變數未定義等 舉例: Notice: Undefined variable: p in E:\web\index.php on line 17 |
| 16 |
E_CORE_ERROR |
PHP進程在啟動時,發生了致命性錯誤 舉例: 暫無 |
| 32 |
E_CORE_WARNING |
在PHP啟動時警告(非致命性錯誤) 舉例: 暫無 |
| 64 |
E_COMPILE_ERROR |
編譯時間致命性錯誤 舉例: 暫無 |
| 128 |
E_COMPILE_WARNING |
編譯時間警告級錯誤 舉例: 暫無 |
| 256 |
E_USER_ERROR |
使用者自訂的錯誤訊息 舉例: 暫無 |
| 512 |
E_USER_WARNING |
使用者自訂的警告訊息 舉例: 暫無 |
| 1024 |
E_USER_NOTICE |
使用者自訂的提醒訊息 舉例: 暫無 |
| 2047 |
E_ALL |
以上所有的報錯資訊,但不包括E_STRICT的報錯資訊 舉例: 暫無 |
| 2048 |
E_STRICT |
編碼通訊協定化警告,允許PHP建議如何修改代碼以確保最佳的互通性向前相容性。 |
error_reporting 變數的預設值是 E_ALL & ~E_NOTICE
開發時,最佳的值為: E_ALL | E_STRICT
如果設定為:error_reporting(E_ALL | E_STRICT),則表示記錄所有的錯誤資訊
可能會導致網站出現一大堆的錯誤碼;但是對於程式員來說應該說是一件好事,可以把代碼最佳化到最優; 一些非致命性錯誤雖然不影響程式的運行,但是會加重PHP的負擔.
最後,曬出英文版的對照表:
| 1 |
E_ERROR |
Fatal run-time errors. Errors that can not be recovered from. Execution of the script is halted |
| 2 |
E_WARNING |
Non-fatal run-time errors. Execution of the script is not halted |
| 4 |
E_PARSE |
Compile-time parse errors. Parse errors should only be generated by the parser |
| 8 |
E_NOTICE |
Run-time notices. The script found something that might be an error, but could also happen when running a script normally |
| 16 |
E_CORE_ERROR |
Fatal errors at PHP startup. This is like an E_ERROR in the PHP core |
| 32 |
E_CORE_WARNING |
Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core |
| 64 |
E_COMPILE_ERROR |
Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine |
| 128 |
E_COMPILE_WARNING |
Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine |
| 256 |
E_USER_ERROR |
Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error() |
| 512 |
E_USER_WARNING |
Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error() |
| 1024 |
E_USER_NOTICE |
User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error() |
| 2048 |
E_STRICT |
Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code |
| 4096 |
E_RECOVERABLE_ERROR |
Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler()) |
| 8191 |
E_ALL |
All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0) |
php error reporting 報告有什類型的錯誤報表
error_reporting()
在php中有四種類型的錯誤和警告。它們是:
通常函數錯誤:1
通常警告:2
分析錯誤:4
注釋(警告使用者,可以忽略該資訊,但是這個問題可能給您的代碼會帶來一些錯誤):8
資訊後面的四個數字是該資訊類型的表示值,把它們加起來作為錯誤報表的層級。卻省的報告層級是7(即1+2+4),或除了“注釋”的其他組合。這個層級能夠通過改變php3.ini檔案中錯誤報表指示的方法來改變。它也可以在使用者的httpd.conf檔案中改變php3錯誤報表的方法來設定,或者在啟動並執行時候使用指令碼語言函數error_reporting()來改變
在PHP中,error_reporting(0)表示什?
不讓PHP報告有錯語發生。如果不關閉好有類似這樣的錯語
Warning: preg_match()
關閉就不出現了
http://www.bkjia.com/PHPjc/840752.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/840752.htmlTechArticlePHP的error_reporting錯誤層級變數對照表,errorreporting 在PHP中所有的報錯資訊可以用error_reporting()這個函數來設定: 它的參數有字串和數字兩...