Skip to content

array_pop when array is list of string and size is known. #12675

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

Closed
TheMarlboroMan opened this issue Mar 3, 2025 · 0 comments · Fixed by phpstan/phpstan-src#4036
Closed

array_pop when array is list of string and size is known. #12675

TheMarlboroMan opened this issue Mar 3, 2025 · 0 comments · Fixed by phpstan/phpstan-src#4036
Labels

Comments

@TheMarlboroMan
Copy link

Bug report

Hi:

We got an assign.propertyType error in the following snippet

Assuming that explode returns a list of strings and since the size has already been asserted to be of two (or else we would throw), why would any call to array_shift or array_pop return null as long as the array has elements?

We tested this same code with direct array access ($pieces[0] and $pieces[1]) and everything is fine.

Code snippet that reproduces the problem

https://phpstan.org/r/f80ce8d4-5b2c-40f3-bd56-48ee5998a24f

Expected output

We would expect no issue to be detected. Please, correct us if we are wrong.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan makes me very, very, very happy on a daily basis. I feel much more confident in our codebase and it has helped us catch many obscure and insidious potential problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants