PHP错误级别处置,隐藏错误信息
PHP错误级别:
1.最低级别错误—Deprecated
if(ereg('china','this is china',$matches)){print_r($matches);
}else{echo 'not find';
}
2.通知级别错误—Notice(抛出报错信息,程序继续向下执行)
echo $num;
3.忠告级别错误—Warning
4.致命级别错误—Fatal(抛出报错信息,程序不能向下执行)
5.语法剖析错误—Parse(最高级别错误,程序不能执行)
1.显示所有错误一:
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 warningserror_reporting = E_ALL&~E_NOTICR&E_DEPRECATED&~E_STRICT
4.PHP通过trigger_error()触发PHP错误
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 '程序继续向下执行!';
原文链接:https://www.cnblogs.com/ccw869476711/p/12846525.html
本站声明:网站内容来源于网络,若有侵权,请联系我们,我们将及时处置。