Valid use cases for at-sign in php

前端 未结 6 1394
天命终不由人
天命终不由人 2021-01-23 09:16

The at sign is used to hide error messages. As far as I see, there is absolutely no use case or excuse for using it.

  1. You can hide errors in production by changing
6条回答
  •  旧时难觅i
    2021-01-23 09:47

    There is some value to the @ sign, but it's normally a code smell.

    Consider the following: you're developing a library that needs to be compatible with multiple projects, and you don't want to change the error handler globally. Unfortunately, many PHP functions (including the sockets and streams related ones) throw a PHP error rather than an exception on failure. The "@" sign is then useful for hiding the error if and only if the error is then checked for manually and an exception is thrown if it occurred.

    It's also useful for filesystem operations.
    Mainly you're right though...it's normally terrible practice (:

提交回复
热议问题