Skip to content

Unable to infer the parameter count when argument unpacking is used. #3631

@bcremer

Description

@bcremer

Bug report

PHPStan is unable to infer the parameter count when argument unpacking is used.

Code snippet that reproduces the problem

In the following example the count() should specify the count of $ids as > 2. Unpacking the $ids array will result in 2 or more parameters.

function someFunc(bool $flag): array 
{
	$ids = [['fa', 'foo', 'baz']];

	if ($flag) {
		$ids[] = ['foo', 'bar', 'baz'];
	}

	if (count($ids) > 1) {
		return array_intersect(...$ids);
	}
	
	return $ids[0];
}
Function array_intersect invoked with 1 parameter, at least 2 required.

https://phpstan.org/r/9e875048-2e14-42de-b846-1dc04c67c0aa

This is a regression or new false positive in 0.12.33.

Expected output

count should be able to specify the parameter count when array unpacking is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions