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

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

    Just speculating, but this could be used to be handled by a custom error handler.

    Example:

    set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
    {
        //Log the error 
    
        // error was suppressed with the @-operator
        if (0 === error_reporting()) { 
            return false;
        }
       // handle error
    
     }
    

    Therefore the error can be logged (or otherwise handled) even if it is suppressed.

    You can't know exactly why this is done unless there's documentation about it. It's up to the developers to explain why they do this.

提交回复
热议问题