How can I reliably identify a specific error in PHP?

后端 未结 4 1834
太阳男子
太阳男子 2021-01-14 19:31

Because of PHP\'s unlink() not supporting exceptions natively, I\'m making a wrapper function for it. It should throw a FileNotFoundException if, w

4条回答
  •  囚心锁ツ
    2021-01-14 19:59

    While reading trough my old questions I came across the ErrorException, combined with set_error_handler() this would be a automatic Error to Exception transformer for all native PHP errors:

    function exception_error_handler($errno, $errstr, $errfile, $errline ) {
        throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
    set_error_handler("exception_error_handler");
    
    /* Trigger exception */
    unlink('Does not exitsts'); 
    

    Can anybody prof this?

提交回复
热议问题