Can I try/catch a warning?

前端 未结 11 1033
孤城傲影
孤城傲影 2020-11-22 01:04

I need to catch some warnings being thrown from some php native functions and then handle them.

Specifically:

array dns_get_record  ( string $hostnam         


        
11条回答
  •  灰色年华
    2020-11-22 01:53

    The solution that really works turned out to be setting simple error handler with E_WARNING parameter, like so:

    set_error_handler("warning_handler", E_WARNING);
    dns_get_record(...)
    restore_error_handler();
    
    function warning_handler($errno, $errstr) { 
    // do something
    }
    

提交回复
热议问题