Skip to content

More precise array_key_first/array_key_last inference - #4994

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

staabm merged 9 commits into
phpstan:2.1.xfrom
staabm:bug14081

Conversation

@staabm

@staabm staabm commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

@phpstan-bot

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

This pull request has been marked as ready for review.

@staabm

staabm commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

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

Comment thread src/Analyser/TypeSpecifier.php Resolved

@VincentLanglet VincentLanglet left a comment

Copy link
Copy Markdown
Contributor

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

staabm commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

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

staabm commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

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