phpconditional-statementscharisset

In php using @ instead of isset


In some conditions, may I use an @ character instead of using the longer isset() function? If not, why not?

I like to use this because in a lot cases I can save several quotation marks, brackets and dots.


Solution

  • I assume you're talking about the error suppression operator when you say @ character, but that isn't a replacement for isset().

    isset() is used to determine whether or not a given variable already exists within a program, to determine if it's safe to use that variable.

    What I suspect you're doing is trying to use the variable regardless of its existance, but supressing any errors that may come from that. Using the @ operator at the beginning of a line tells PHP to ignore any errors and not to report it.

    The @ operator is shorthand for "temporarily set error_reporting(0) for this expression". isset() is a completely different construct.