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
  • 16,129
  • 24
  • 81
  • 95

1 Answers1

6

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
  • 166,037
  • 39
  • 233
  • 307