- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-best-practices/avoid-silencing-errors
Language: PHP
Severity: Warning
Category: Error Prone
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:
try {
canThrowAnError();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
This way, you can manage the error and take appropriate action, rather than ignoring it.
<?php
@canThrowAnError();
<?php
canThrowAnError();
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products