Skip to content

Destructuring syntax (list() and []) #119

Open
@j-willette

Description

@j-willette

I want to report a case that does not seem to be explicitly covered by PSR-12.
It concerns variable destructuring using the list() and [] syntaxes.

I have this code:

[$val1,$val2] = explode(',', $string);
list($val1,$val2) = explode(',', $string);

And I do not get any error when running the command:

phpcs --standard=PSR12 my-file.php

In my opinion, there should be a space required after the comma following $val1, as in function calls or arrays.

Correction:

[$val1, $val2] = explode(',', $string);
list($val1, $val2) = explode(',', $string);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions