Skip to content

@phpstan-ignore-line not working on last array line #4759

@WillyReyno

Description

@WillyReyno

Bug report

When trying to ignore a few specific lines within an array I noticed that // @phpstan-ignore-line was not working if my array contained only one key or if the key I was trying to ignore was the last one.

Code snippet that reproduces the problem

Last key not ignored

The following code where $a & $c dont exist on $device

[
    'a' => $device->a, // @phpstan-ignore-line
    'b' => $device->b,
    'c' => $device->c, // @phpstan-ignore-line
];

PHPStan only ignores $a while $c should also have been ignored.

 ------ ----------------------------------------------------------- 
  Line   MyClass.php         
 ------ ----------------------------------------------------------- 
  188    Access to an undefined property App\Models\Device::$c.   

Only key not ignored

[
    'a' => $device->a, // @phpstan-ignore-line
];

PHPStan reports :

 ------ ----------------------------------------------------------- 
  Line   MyClass.php  
 ------ ----------------------------------------------------------- 
  186    Access to an undefined property App\Models\Device::$a.   

Expected output

PHPStan shouldn't have reported the ignored lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions