I've got some variables that may or may not be defined (an $isLoggedIn
boolean) and I'm trying to clean out the error messages. I was wondering if there was any reason I shouldn't use the error suppressor operator:
if (@$isLoggedIn)
Or if I should instead check the existance of the variable first:
if (isset($isLoggedIn)and$isLoggedIn)
In a production environment is there any drawback/benefit to either approach in particular? The functionality of both statements is identical and there are no problems caused by this var being undefined. It shouldn't be logged as an error though.
In my experience, you should never suppress errors on an individual level. In your production environment set error reporting to 0 and display errors to off. Having individual supressions like this is shooting yourself in the foot when you come back to fix an error in 6 months, forget it's there and can't work out why no errors are showing up but something is clearly broken.
In you particular case, just set $isLoggedIn to false then override that value at the location you are currently instantiating it (I'm assuming code structure here).
If you're using a variable, it should exist. Your code shouldn't suppress errors, you should fix them or deal with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With