If I get a variable and I don't know is it set or not I can write
if (isset($a) && $a > 2)
or I can write
if (@ $a > 2)
which is shorter. Is the second syntax good or not?
Overview. Code MUST follow a "coding style guide" PSR [PSR-1]. Code MUST use 4 spaces for indenting, not tabs. There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.
It's versatile: One of the major benefits of PHP is that it is platform independent, meaning it can be used on Mac OS, Windows, Linux and supports most web browsers. It also supports all the major web servers, making it easy to deploy on different systems and platforms at minimal additional cost.
The expression if(@$a)
does not check whether the variable is set or not. The @ symbol just surpresses any warnings which is a bad coding style.
I totally sympathize, but suppressing the error using @
is bad practice.
The error still occurs, it just gets suppressed. It costs microscopical amounts of time that can however accumulate to a lot if done in loops.
Also, you take away the possibility to use "undefined variable" notices to your advantage: As a mechanism to avoid typos.
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