溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PHP報錯信息的函數(shù)說明

發(fā)布時間:2021-09-13 17:43:38 來源:億速云 閱讀:137 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要講解了“PHP報錯信息的函數(shù)說明”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“PHP報錯信息的函數(shù)說明”吧!

在PHP中所有的報錯信息可以用error_reporting()這個函數(shù)來設(shè)置:

它的參數(shù)有字符串和數(shù)字兩種表示方法,共14個等級,但是呢,我看使用其他數(shù)字貌似也可以,起初我以為它指的是一定的報錯區(qū)間,后來,終于發(fā)現(xiàn)了其中的規(guī)律:

復(fù)制代碼 代碼如下:

error_reporting( 7 ) = error_reporting( 1+2+4)= error_reporting(E_ERROR | E_WARING | E_PARSE)

現(xiàn)在,我將其總結(jié)如下:

數(shù)字常量說明
1E_ERROR致命錯誤,腳本執(zhí)行中斷,就是腳本中有不可識別的東西出現(xiàn)
 舉例: Error:Invalid parameters. Invalid parameter name
2E_WARNING部分代碼出錯,但不影響整體運行
 舉例: Warning: require_once(E:/include/config_base.php)
4E_PARSE 字符、變量或結(jié)束的地方寫規(guī)范有誤
 舉例:  Parse error: syntax error, unexpected $end in
 E_NOTICE一般通知,如變量未定義等
 舉例:  Notice: Undefined variable: p in E:\web\index.php on line 17
16 E_CORE_ERRORPHP進程在啟動時,發(fā)生了致命性錯誤
 舉例:  暫無
32 E_CORE_WARNING在PHP啟動時警告(非致命性錯誤)
 舉例:  暫無
64E_COMPILE_ERROR編譯時致命性錯誤
 舉例:  暫無
128E_COMPILE_WARNING編譯時警告級錯誤
 舉例:  暫無
256E_USER_ERROR 用戶自定義的錯誤消息
 舉例:  暫無
512E_USER_WARNING用戶自定義的警告消息
 舉例:  暫無
1024E_USER_NOTICE 用戶自定義的提醒消息
 舉例:  暫無
2047E_ALL以上所有的報錯信息,但不包括E_STRICT的報錯信息
 舉例:  暫無
2048E_STRICT編碼標(biāo)準(zhǔn)化警告,允許PHP建議如何修改代碼以確保最佳的互操作性向前兼容性。

error_reporting 變量的默認(rèn)值是  E_ALL & ~E_NOTICE
開發(fā)時,最佳的值為: E_ALL | E_STRICT

如果設(shè)置為:error_reporting(E_ALL | E_STRICT),則表示記錄所有的錯誤信息
可能會導(dǎo)致網(wǎng)站出現(xiàn)一大堆的錯誤代碼;但是對于程序員來說應(yīng)該說是一件好事,可以把代碼優(yōu)化到最優(yōu); 一些非致命性錯誤雖然不影響程序的運行,但是會加重PHP的負(fù)擔(dān).


最后,曬出英文版的對照表:

1E_ERRORFatal run-time errors. Errors that can not be recovered from. Execution of the script is halted
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191E_ALLAll errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)

感謝各位的閱讀,以上就是“PHP報錯信息的函數(shù)說明”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對PHP報錯信息的函數(shù)說明這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI