How to suppress the “Division by zero” error and set the result to null for the whole application?

前端 未结 4 1040
小鲜肉
小鲜肉 2020-12-20 13:29

How to suppress the \"Division by zero\" error and set the result to null for the whole application? By saying \"for the whole application\", I mean it is n

4条回答
  •  隐瞒了意图╮
    2020-12-20 14:15

    This is a horrible solution, but thankfully, you won't use it because the variable is set to false instead of null.

    function ignore_divide_by_zero($errno, $errstring)
    {
      return ($errstring == 'Division by zero');
    }
    
    set_error_handler('ignore_divide_by_zero', E_WARNING);
    

    In your case, I'd create a function that does your division for you.

提交回复
热议问题