如何在這個php函數中禁止E_NOTICE,我不想從生產站點獲取有關非declaret變量的電子郵件?set_error_handler,如何在php中禁止E_NOTICE
我已經嘗試過評論情況E_NOTICE:但是然後該程序只是跳轉到默認值:退出(「未知的錯誤在$ errfile:$ errline」);靠近腳本的末尾。
我想有機會評論出我不想要的錯誤反饋?語句後
<?php
function errorHandler($errno, $errstr, $errfile, $errline) {
function errorMail($errno, $errstr, $errfile, $errline) {
$recvmail = "yourmail";
$fejlkode = array(
1 => "E_ERROR",
2 => "E_WARNING",
4 => "E_PARSE",
8 => "E_NOTICE",
16 => "E_CORE_ERROR",
32 => "E_CORE_WARNING",
64 => "E_COMPILE_ERROR",
128 => "E_COMPILE_WARNING",
256 => "E_USER_ERROR",
512 => "E_USER_WARNING",
1024 => "E_USER_NOTICE",
2048 => "E_STRICT",
4096 => "E_RECOVERABLE_ERROR",
8192 => "E_DEPRECATED",
16384 => "E_USER_DEPRECATED",
);
$mail = new PHPMailer;
$mail->From = 'mailSender';
$mail->FromName = 'your firm name';
$mail->AddAddress($recvmail, "your name"); // Add a recipient
$mail->SetLanguage('dk', './');
$mail->Subject = utf8_decode("Fejl type:" . $errno .' -> '. $fejlkode[$errno]);
$mail->Body = utf8_decode($errstr.' <br>'.$errfile.': '.$errline);
$mail->AltBody = $errstr.$errfile.$errline.$errno;
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
}
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_STRICT:
errorMail($errno, $errstr, $errfile, $errline);
break;
case E_WARNING:
case E_USER_WARNING:
errorMail($errno, $errstr, $errfile, $errline);
break;
case E_ERROR:
case E_USER_ERROR:
errorMail($errno, $errstr, $errfile, $errline);
exit("FATAL error $errstr at $errfile:$errline");
default:
exit("Unknown error at $errfile:$errline");
}
}
set_error_handler("errorHandler");
?>
不要禁止警告。解決導致他們擺在首位的問題。 –
_我不想收到電子郵件,關於未聲明的變量_ - 是的。 PHP對未聲明的變量做出假設,這些變量可能不符合您的期望。正常運行時,生產現場不應該生成任何消息。 – 2014-02-14 09:12:54
顯示所有錯誤,但E_NOTICE和E_USER_NOTICE除外。 set_error_handler(「errorHandler」,E_ALL&〜E_NOTICE&〜E_USER_NOTICE); – Anders