PHP unlink() handling the exception

前端 未结 7 1105
南旧
南旧 2020-12-15 15:48

Well, I have been wondering if I can handle the unlink() function properly. I dont want the unlink() function to throw some nasty error if it is un

7条回答
  •  死守一世寂寞
    2020-12-15 16:48

    unlink doesn't throw exceptions, in generates errors. The proper way to do this is check that the file exists before trying to call unlink on it. If you are merely worried about not having the errors output then you should just turn off display_errors which you should always do in a production environment anyway. Then they will just be logged.

    Do not suppress errors with the @, its rarely advisable.

    Can you be more descriptive about @

    Im not sure what you mean exactly. But the documentation is here. As far as why you don't want to use it... That is because then you never know that code isn't working or is problematic. Even if the code still works from a functional perspective it's still got an issue and that issue could potentially make something else completely not work at some point. If you never have the error you'll probably waste a lot of time debugging.

    Its fine to change your log level or disable the display of errors, but you never want to completely suppress them.

提交回复
热议问题