Skip to content

"Empty array passed to foreach" false positive (in array of array) #2560

@phrounz

Description

@phrounz

Bug report

phpstan gives error "Empty array passed to foreach." within an associative array with arrays as values, but those internal arrays are not empty.

Code snippet that reproduces the problem

https://phpstan.org/r/579c6091-9983-45ee-bcfa-54565c3d38be

Expected output

no error

Notes

Note that there are no errors if we replace
foreach ([0,1] as $i) {
by
foreach ([0] as $i) {

or if we replace:
$arr[$i] = [];array_push($arr[$i], "foo");
by
$arr[$i] = ["foo"];

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions