你能帮我正确设置 php set_error_handler吗?我需要处理将 php警告作为异常抛出的代码。但我不知道如何正确地做到这一点。现在我有了这段代码,我认为这是不正确的。
set_error_handler( function( $errno, $errstr, $errfile, $errline, array $errcontext )
{
throw new \Exception( $errstr, $errno );
});
$mailer->send( $mail );
restore_error_handler();
正如我在文档中看到的那样,它需要更复杂的解决方案。但我对所有这些常数有点困惑。有没有办法以某种优雅的方式设置它,不会单独设置所有常量。我的意思是:
function( $errno, $errstr, $errfile, $errline, array $errcontext )
{
if( $errno >= E_USER_WARNING ) throw new \Exception( $errstr, $errno );
});
那么如何以某种优雅的方式将php警告包含到异常中。谢谢。