Skip to content

Generic.Arrays.DisallowShortArraySyntax creates fatal error #3709

Open
@kkmuffme

Description

@kkmuffme

Describe the bug

Generic.Arrays.DisallowShortArraySyntax.Found creates a fatal when it's an array assignment, where it should replace with list, not array

Code sample

[, $foo] = explode( '=', 'hello=world=bar', 2 );

Will be changed to:

array(, $foo) = explode( '=', 'hello=world=bar', 2 );

which is invalid and a fatal error.
If short array is followed by assignment (=), it should be changed to:

list(, $foo) = explode( '=', 'hello=world=bar', 2 );

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
    <rule ref="Generic.Arrays.DisallowShortArraySyntax"/>
</ruleset>

To reproduce
use the above code sample with the custom ruleset and run phpcbf --standard=custom-ruleset.xml code-sample.php on it

Expected behavior

Change it to:

list(, $foo) = explode( '=', 'hello=world=bar', 2 );

Versions (please complete the following information):

  • OS: RHEL 8
  • PHP: 7.4
  • PHPCS: 3.7.1
  • Standard: single rule

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions