- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-code-style/objects-ensure-use
Language: PHP
Severity: Warning
Category: Error Prone
This rule requires that all newly created objects in PHP should be used in your code. Creating an object with the new
keyword but not using it is considered a violation of this rule. This prevents the creation of unnecessary objects that take up memory and can slow down your application’s performance.
In PHP, when you create an object using the new
keyword, it allocates memory for that object. If the object isn’t used, this memory allocation is wasted. This can lead to memory leaks and performance issues, especially in larger applications.
To avoid violating this rule, always assign your new objects to a variable or use them directly after creation. For instance, $obj = new Object;
is compliant code as the newly created object is assigned to a variable named $obj
. On the other hand, new Object;
is non-compliant code because the newly created object is not being used or assigned to any variable. Following this rule leads to more efficient, cleaner code.
<?php
new Object;
<?php
$obj = new Object;
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products