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

Asked

Viewed 659 times

17

What is the function of @ at the beginning of PHP expressions?

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

1 answer

17


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

In some rare cases its mandatory use, because some functions of php still release the error message carelessly or is an unexpected text output that can generate a Cannot Modify header information - headers already sent by

An example is the function mkdir and fopen, the manual says that your return is Boolean, but beyond the false one warning is generated.

An example of the misuse of arroba (@) is to hide a warning, the common Undefined index ...

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

Do:

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

 ou

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

Related:

Why do they say using @arroba to suppress errors is a bad practice?

References:

Why Suppressing Notices is Wrong

Suppress error with @ Operator in PHP - Soen

  • I’ve seen this in large and widely used frameworks and library classes

  • Which framework?

  • 1

    @rray bet all my chips on Codeigniter xD

  • @gmsantos, I thought the same thing and how you have arroba. There was a framework that was based on CI if I’m not mistaken it was kohana, if based on CI there is something wrong there haha

  • Phpcrawl, a framework for development based on PHP components that I don’t remember the name

Browser other questions tagged

You are not signed in. Login or sign up in order to post.