Skip to content

Fix array_column inference #4201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.1.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
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
Collaborator

This pull request has been marked as ready for review.

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
2 participants