Skip to content
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

non-empty-array seems to be incorrectly identified as possibly empty after unset #11096

Open
cfahner opened this issue May 28, 2024 · 2 comments

Comments

@cfahner
Copy link

cfahner commented May 28, 2024

Bug report

A property marked as non-empty-array seems to be incorrectly identified as possibly empty. This is after explicitly checking if the array has at least two items before using unset() on it.

Code snippet that reproduces the problem

https://phpstan.org/r/8d223a39-663d-42ba-803d-1ae7644ded48

Expected output

No errors as the array should have at least one item left.

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

Very happy with PHPStan! Prevented a lot of headaches so far.

@ondrejmirtes
Copy link
Member

PHPStan does not track specific array sizes above 1 yet.

@ondrejmirtes
Copy link
Member

/cc @herndlm Hypothetical "AccessoryArraySizeType" would be really helpful for this and other cases. I'd be able to use it in phpstan/phpstan-src#3865 too which fixes about 5-6 issues now.

The accompanying Type::getArraySize() method is already there. The new type could be used to track the precise sizes of general arrays. Of course the biggest challenge would be to have it always up-to-date, after all operations.

Is this something you'd like to tackle?

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

No branches or pull requests

2 participants