Skip to content

Array count in match results in incorrect offset error in lower branch of match #10952

@Grldk

Description

@Grldk

Bug report

I have some code similar to this:

		$return = match (true) {
			count($array) > 1 => $array[1],
			default => $array[0] ?? 'empty',			
		};

Phpstan reports an offset error on $array[0].

Code snippet that reproduces the problem

https://phpstan.org/r/3f2b24c5-b3b3-4dcb-b46c-685973482e53

Expected output

No errors should be given I think.

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

Phpstan really helps us maintaining our code quality to a reasonable level, thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions