- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-best-practices/no-self-assign
Language: PHP
Severity: Notice
Category: Error Prone
This rule aims to prevent redundancy in code. Assigning a variable to itself is a pointless operation that can lead to confusion and clutter in the code, making it harder to read and understand. It’s also a potential indicator of a mistake or oversight in the code, where a different assignment was intended.
This rule is important because clean, efficient code is a hallmark of good programming. Unnecessary assignments can slow down the runtime of the script and, more importantly, make the code harder to maintain and debug. In a large codebase, such redundancies can add up to significant inefficiencies.
To avoid this, always ensure that the right-hand side of an assignment is not the same as the left-hand side. If you find yourself writing var = var
, it’s probably a mistake. Double-check your code to ensure that you’re assigning the correct variables. If you’re reassigning a variable to itself intentionally, consider whether this is really necessary and if there might be a cleaner way to achieve your goal.
<?php
$var = 1;
$var2 = 2;
$var = $var;
<?php
$var = 1;
$var2 = 2;
$var = $var2;
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products