Why can't you hide errors with the @
operator when calling unset
? The following results in a parse error:
@unset($myvar);
The @
operator only works on expressions, and unset
is a language construct, not a function. See the manual page for more information:
Note: The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include() calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.
You can hide errors by prefixing @ to functions/statements. However unset is a language construct, therefore it doesn't support the @-rule.
The good thing is that unset() never fails even if the variable didn't exist to begin with, so this shouldn't be necessary.
As nightcracker mentionned though, using @ is pretty bad practice.
The error suppression operator only works on expressions:
unset
is a language construct and not a function, so @
cannot be used.
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