What is the function of '@' (at) at the beginning of expressions in PHP

13

What is the function of @ at the start of expressions in PHP?

I have seen in some classes and I could not get the function to put this @ at startup.

    
asked by anonymous 10.02.2015 / 15:13

1 answer

13

@ error control operator at start of function call or variable is hide the error message. It is not recommended to do this because it masks erro/warning and leaves its detection more subtle.

In some rare cases its mandatory use, because some functions of php still throw the error message in a careless way, or an unexpected text output that can generate a Can not modify header information already ->

An example is the mkdir and fopen , the manual says its return is boolean, but in addition to false a warning is generated.

An example of the misuse of at sign ( @ ) is to hide a warning , the common undefined index ...

$id = @$_GET['id'];

Make:

$id = isset($_GET['id']) ? $_GET['id'] : '';

 ou

$id = ''; 
if(isset($_GET['id'])){
   $id = $_GET['id];
}

Related:

Why do you say that using @ atm to suppress errors is bad practice?

References:

Why Suppressing Notices is Wrong

Suppress error with @ operator in PHP - SOen

    
10.02.2015 / 15:15