Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Array destructuring of item in foreach is not properly checked #8075

@olsavmic

Description

@olsavmic

Bug report

When array destructuring is used on item inside foreach, non-existent keys are not reported even though the shape of array is well defined. Array destructuring otherwise works during regular assignment. See the linked code snipped for more details.

$arr = [['a' => 0]];

['b' => $val] = $arr[0]; // Works just fine, error is reported

foreach ($arr as ['b' => $valueB]) { // no error reported

}

Code snippet that reproduces the problem

https://phpstan.org/r/1551cc74-364f-4d99-96a8-4847ff8e084f

Expected output

Missing 'b' key should be reported.

Did PHPStan help you today? Did it make you happy in any way?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions