- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-best-practices/prefer-require-include-once
Language: PHP
Severity: Warning
Category: Error Prone
This rule emphasizes the importance of using require_once
or include_once
instead of require
or include
in PHP. The main reason behind this is to avoid the inclusion of the same file more than once. If a file is included multiple times, it may lead to function redefinitions, variable value reassignments, and other unexpected behaviors which can be hard to debug.
require_once
and include_once
are statements that handle this problem effectively. They check if the file has already been included, and if so, they do not include it again. This ensures that the code within the file is executed only once, maintaining the integrity of your PHP application.
To comply with this rule, always use require_once
or include_once
when you want to include a PHP file. This will help to prevent potential issues with function redefinition or variable reassignment, and will make your code more reliable and easier to manage.
<?php
require 'file.php';
include 'file.php';
<?php
require_once 'file.php';
include_once 'file.php';
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products