Skip to content

Improve ConstantArrayType::sliceArray() with non constant integer args #3949

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

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Apr 18, 2025

ConstantArrayType::sliceArray() is one of the more complex constant array methods I once came up with. But it can only handle constant integer offsets and lengths so far. I tried to add support for e.g. unions, but this would increase complexity even more.

Currently there is an issue where it naively falls back the defaults (offset 0, length null = full array) when it encounters invalid values. Instead of that, I think it's better and safer to degrade to a general array and do the slice there to avoid incorrect types.

@ondrejmirtes ondrejmirtes merged commit f78547c into phpstan:2.1.x Apr 19, 2025
417 of 418 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the constant-array-slice-array-non-constant-integer-types branch April 19, 2025 12:09
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.

2 participants