Skip to content

More precise array_key_first/array_key_last inference#4994

Merged
staabm merged 9 commits intophpstan:2.1.xfrom
staabm:bug14081
Feb 19, 2026
Merged

More precise array_key_first/array_key_last inference#4994
staabm merged 9 commits intophpstan:2.1.xfrom
staabm:bug14081

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 19, 2026

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm changed the base branch from 2.2.x to 2.1.x February 19, 2026 09:30
@staabm staabm marked this pull request as ready for review February 19, 2026 09:34
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Feb 19, 2026

I will look into a similar optimization for other hardcoded functions in a separate PR

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Does it works if $key = array_key_last($array) is done before the if ?

@staabm
Copy link
Contributor Author

staabm commented Feb 19, 2026

added a test which I think covers your question

@staabm staabm merged commit ff98196 into phpstan:2.1.x Feb 19, 2026
636 of 642 checks passed
@staabm
Copy link
Contributor Author

staabm commented Feb 19, 2026

thank you

@staabm staabm deleted the bug14081 branch February 19, 2026 11:34
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

Comments