1

Curious as to situations you would mask error messages in PHP using the "@" expression instead of fixing the error.

nopnotme
  • 21
  • 6
  • 3
    I'd like to know the answer, but this seems primarily opinion-based. – FirstOne Nov 29 '17 at 18:11
  • 1
    Virtually never. You could probably get away with `if(@$_POST['foo']) {}` to avoid having to do an `isset()` check. – ceejayoz Nov 29 '17 at 18:13
  • 1
    @ceejayoz could you see a project using @ and still be considered stable? More so, I guess my question is if '@' is accepted as standard practice in final projects? I've always thought @ is only temporary way to mute messages but should never be left when publishing your completed work. – nopnotme Nov 29 '17 at 18:19
  • 1
    To expand on the answer from @ceejayoz -- there is virtually never a legit reason to use `@`, *even in development*. Don't mute messages. Standard practice is to write code that doesn't generate them. – Alex Howansky Nov 29 '17 at 18:30
  • TIL thanks @AlexHowansky – nopnotme Nov 29 '17 at 18:32
  • 1
    Also note the new `??` operator is wonderful for shortcuts to avoid lots of `isset()` calls. – Alex Howansky Nov 29 '17 at 18:34
  • Could you link me Alex? I don't see any documentation yet, what version of php? – nopnotme Nov 29 '17 at 18:43
  • @nopnotme https://lornajane.net/posts/2015/new-in-php-7-null-coalesce-operator – ceejayoz Nov 29 '17 at 18:54

0 Answers0