3 回答
TA贡献1805条经验 获得超9个赞
设置和恢复错误处理程序
restore_error_handler().
set_error_handler(function() { /* ignore errors */ });dns_get_record();restore_error_handler();set_error_handler([$logger, 'onSilencedError']);dns_get_record();restore_error_handler();
将错误转化为例外
set_error_handler()ErrorException
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);});try {
dns_get_record();} catch (ErrorException $e) {
// ...}error_reportingset_error_handler()... = error_reporting()
抑制警告
dns_get_record()
TA贡献1784条经验 获得超9个赞
E_WARNING
set_error_handler("warning_handler", E_WARNING);dns_get_record(...)restore_error_handler();function warning_handler($errno, $errstr) {
// do something}TA贡献1829条经验 获得超7个赞
@@mysql_query( '...' )
bob@mypc:~$ php -aInteractive shell php > echo @something(); // this will just silently die...
bob@mypc:~$ php -aInteractive shell
php > echo something(); // lets try it again but don't suppress the errorPHP Fatal error:
Call to undefined function something() in php shell code on line 1PHP Stack trace:PHP 1. {main}() php shell code:0bob@mypc:~$- 3 回答
- 0 关注
- 312 浏览
添加回答
举报
