Why this matters
Using '@' hides errors that may indicate serious issues, making bugs hard to find and fix. It also incurs a performance cost. Explicit error handling ensures code reliability.
Do not use the error‐suppression operator '@' before function calls or expressions. Instead, handle potential errors properly using return checks or exceptions (try/catch).
Using '@' hides errors that may indicate serious issues, making bugs hard to find and fix. It also incurs a performance cost. Explicit error handling ensures code reliability.
Side-by-side examples engineers can pattern-match during review.
<?php
$file = @file_get_contents('data.txt');
?><?php
$file = file_get_contents('data.txt');
if (\$file === false) {
error_log('Failed to read data.txt');
}
?><?php
$file = @file_get_contents('data.txt');
?><?php
$file = file_get_contents('data.txt');
if (\$file === false) {
error_log('Failed to read data.txt');
}
?>From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.