0

Is writing:

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

instead of:

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

is some bad coding practice? Can I use @ as a normal operator or only in some specific cases?

Dawid Ohia
  • 15,440
  • 22
  • 76
  • 94

1 Answers1

5

Yes, using the @ operator is considered bad practice.

It is well documented that it has performance implications.

In addition, supressing error messages is a sign of bad practice; you should write your code to expect errror and handle them defensively. Simply swallowing the errors behind an @ symbol means that your code will never know that the error occurred, nor what the error actually was; this can often lead to further problems later in your code.

There are some cases where it is unavoidable to use @ but this is not one of them, so you should avoid doing it.

Spudley
  • 161,975
  • 39
  • 229
  • 303