Separate lines for each declaration

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: php-code-style/single-var-declaration

Language: PHP

Severity: Notice

Category: Best Practices

Description

This rule requires that each variable declaration should be on its own separate line. This is important for readability and maintainability of the code. If multiple variables are declared on the same line, it can be easy to miss a declaration or confuse the values of the variables.

In order to comply with this rule, when declaring multiple variables, each one should be placed on its own line with its own assignment statement. This makes it clear what each variable is and what its initial value is.

Non-compliant code can be corrected by moving each declaration to its own line. For example, instead of writing $field1 = 1, $field2 = 2;, you can write: $field1 = 1; $field2 = 2;. This makes the code easier to read and understand.

Non-Compliant Code Examples

<?php
class Test
{
    $field1 = 1, $field2 = 2;
}

Compliant Code Examples

<?php
class Test
{
    $field1 = 1;
    $field2 = 2;
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis