Skip to content

Narrow list to non-empty-list inside foreach #13312

@gharlan

Description

@gharlan

Feature request

https://phpstan.org/r/847f855b-835a-4ff6-b466-e4b30717076f

/** @param list<mixed> $arr */
function foo(array $arr): void {
	foreach ($arr as $v) {
		bar($arr);
	}

	for ($i = 0; $i < count($arr); ++$i) {
		bar($arr);
	}
}

/** @param non-empty-list<mixed> $arr */
function bar(array $arr): void {}

Inside the foreach loop $arr can not be empty.
It already works when using a for loop instead of foreach.

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

No response

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