- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-security/no-side-effect
Language: PHP
Severity: Warning
Category: Best Practices
Avoiding side effects in a file that defines symbols is an important principle in PHP development. A file should declare symbols (like classes, functions, or constants) and cause no other side effects. Side effects include but are not limited to: generating output, explicit use of require
or include
, connecting to external services, modifying ini settings, emitting errors or exceptions, modifying global or static variables, reading from or writing to a file, and so on.
This rule is essential because it promotes the separation of concerns, which is a fundamental aspect of good software design. It helps to maintain the readability, maintainability, and testability of your code. Side effects can lead to hidden dependencies, making the code harder to understand and manage.
To adhere to this rule, always ensure that your PHP files either define symbols (like classes, functions, or constants) or cause side effects (like generating output or changing ini settings), but not both. For instance, if a file defines a class, it shouldn’t also connect to the database. Instead, the database connection should be done in a different file or within a method or function when needed. This way, you can maintain a clear separation between the definition of your symbols and the implementation of your application logic.
<?php
class Test {
}
print 'testing!';
<?php
class Test {
}
class Main {
}
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products