Skip to content

Add null to array_map(null, $a, $b)#3562

Merged
ondrejmirtes merged 2 commits intophpstan:1.12.xfrom
schlndh:fix-arrayMapZip
Nov 12, 2024
Merged

Add null to array_map(null, $a, $b)#3562
ondrejmirtes merged 2 commits intophpstan:1.12.xfrom
schlndh:fix-arrayMapZip

Conversation

@schlndh
Copy link
Copy Markdown
Contributor

@schlndh schlndh commented Oct 11, 2024

Fixes: https://3v4l.org/QKHrt (https://phpstan.org/r/357b09e6-80b7-4c50-97db-35995ff4cb67)

Unfortunately, since it depends on values of multiple variables at the same time (which may be correlated), there will be false positives like this:

if (rand()) {
	$a = [1];
	$b = [2];
} else {
	$a = [1, 2];
	$b = [3, 4];
}

array_map(null, $a, $b);

But I guess it's better to be safe than sorry. I at least added support for array_map(null, $a, $a).

public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type
{
if (count($functionCall->getArgs()) < 2) {
$numArgs = count($functionCall->getArgs());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, i see multiple call function $functionCall->getArgs(). Can refactor?

@ondrejmirtes ondrejmirtes merged commit d0e7aca into phpstan:1.12.x Nov 12, 2024
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

@schlndh schlndh deleted the fix-arrayMapZip branch November 12, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants