Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:php-best-practices/avoid-silencing-errors
Language: PHP
Severity: Warning
Category: Error Prone
Description
This rule stipulates that errors in your PHP code should not be silenced using the ‘@’ operator. Suppressing errors using this operator is not a good practice as it can make debugging difficult and lead to unexpected behavior in your application.
Errors in your code indicate that something is not functioning as expected. By silencing these errors, you are ignoring potential problems that could lead to bigger issues down the line. Keeping a clean, error-free codebase is essential for maintaining a robust and reliable application.
To avoid breaking this rule, ensure that all potential errors in your code are properly handled. This can be achieved through the use of try/catch blocks or error handling functions. Instead of suppressing an error, handle it appropriately and provide a meaningful response. For instance, you can log the error for later review or display an error message to the user.
For example, instead of writing @canThrowAnError();, you can write: