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.
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.
@
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: