PHP錯誤級別處理,隱藏錯誤信息
PHP錯誤級別:
1.最低級別錯誤---Deprecated
<?php //例 if(ereg('china','this is china',$matches)){ print_r($matches); }else{ echo 'not find'; }
2.通知級別錯誤---Notice(拋出報錯信息,程序繼續向下執行)
<?php //不存在的變量 echo $num;
3.警告級別錯誤---Warning
4.致命級別錯誤---Fatal(拋出報錯信息,程序不能向下執行)
5.語法解析錯誤---Parse(最高級別錯誤,程序不能執行)
<?php echo md5(111); echo md6(1111);//不存在md6函數
1.顯示所有錯誤一:
<?php //顯示所有錯誤 error_reporting(E_ALL&~E_NOTICE); //不顯示所有錯誤 error_reporting(0); //顯示錯誤 error_reporting(-1); //in_set() 運行時設置配置選項的值 in_set('error_reporting',0); in_set('error_reporting',-1);
in_set('display_errors',0);
2.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's 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 error_reporting = E_ALL&~E_NOTICR&E_DEPRECATED&~E_STRICT
4.PHP通過trigger_error()觸發PHP錯誤
<?php header('content-type:text/html;charset=utf-8'); $num1 = 1; $num2 = '3b'; //判斷$num1 和$num2 是否是合法數值 if(!(is_numberic($num1)&& is_numeric($num2))){
//trigger_error('num1 和 num2 必須為合法數值',E_USER_NOTICE); //trigger_error('num1 和 num2 必須為合法數值',E_USER_WARNING);
trigger_error('num1 和 num2 必須為合法數值',E_USER_ERROR);
}else{ echo $num1 + $num2 ; } echo '程序繼續向下執行!';