Skip to content

Fix array_column inference#4201

Merged
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
VincentLanglet:fix/10367
Sep 7, 2025
Merged

Fix array_column inference#4201
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
VincentLanglet:fix/10367

Conversation

@VincentLanglet
Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet commented Aug 3, 2025

Closes phpstan/phpstan#10367

Fix is the first commit 5e252bd

Second commit is just a refacto to reduce the number of method calls 26476e0

Since the method is almost always doing logic like

$type = $this->getOffsetOrProperty(...., false);
if ($type !== null) {
     return type;
} else {
     $type = $this->getOffsetOrProperty(...., true);
     // do things
}

It's better to directly return the type and the certainty and write

[$type, $certainty] = $this->getOffsetOrProperty(...., false);
if ($certainty->yes()) {
     return type;
} else {
     // do things
}

@VincentLanglet VincentLanglet marked this pull request as ready for review August 3, 2025 20:01
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 1efb0ea into phpstan:2.1.x Sep 7, 2025
449 of 454 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

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.

array_column results in non-empty value according to PHPStan

3 participants