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

前端 未结 3 1701
南笙
南笙 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:31

    Adding to what other people said, according to the docs this entire scheme boils down to the following example:

    set_error_handler(function ($errno, $errstr) {
        var_dump($errstr); // outputs "Will only be seen ..."
    }, E_USER_DEPRECATED);
    
    @trigger_error('Will only be seen from a custom error handler', E_USER_DEPRECATED);
    

    Otherwise put, a silenced deprecation notice still can be heard from a custom error handler, if needed, not polluting the usual logs in the same time.

提交回复
热议问题