What is the purpose of '@' (silence operator, at sign) before trigger_error?

前端 未结 3 1848
南笙
南笙 2021-01-22 16:03

I have seen in many Symfony bundles (and also in other codes) this line :

@trigger_error(\'The class is deprecated\', E_USER_DEPRECATED);

Accor

3条回答
  •  半阙折子戏
    2021-01-22 16:46

    As stated in the Symfony coding conventions:

    Without the @-silencing operator, users would need to opt-out from deprecation notices. Silencing swaps this behavior and allows users to opt-in when they are ready to cope with them (by adding a custom error handler like the one used by the Web Debug Toolbar or by the PHPUnit bridge).

    Comment from author about the relevant PR:

    ...There is an other consideration that makes me think this is really the best: performance. We could wrap the implementation of triggering "opt-in deprecation notices" behind some more semantic interface. But that would add overhead to something that needs to be as fast as possible. This is not a micro-optim when this can be called thousands of times. Thus this raw-bare-metal-php implementation that may look hacky, but is just the right implementation for our needs.

提交回复
热议问题