Turn off or handle errors within a production environment?

后端 未结 3 636
无人及你
无人及你 2020-12-18 16:09

After having an argument with my team because we all have different views on this sort of situation.. When is it actually acceptable to turn off PHP error messages, or to su

3条回答
  •  悲&欢浪女
    2020-12-18 16:37

    You never simply turn off error reporting entirely. You do turn off error display. Directly dumping errors to the screen is necessary during development (unless you have other methods which throw all errors in your face), in production you want the same error reporting but instead of it outputting visible errors, you want it to only log them. This can all be done using PHP's error reporting configuration settings.

    If you want special custom error handling/logging, use a custom error handler.

    As for @, you never write your application in a way that it produces actual errors on whose behavior you rely. You write everything in a way that does not trigger errors. You only use @ when there's no way to avoid a possible error because you cannot write it any other way, and you expect an error and are handling it; then all you do it to suppress the inevitable error message.

提交回复
热议问题