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

Unset on a list should report an error #10506

Closed
ondrejmirtes opened this issue Jan 29, 2024 · 8 comments
Closed

Unset on a list should report an error #10506

ondrejmirtes opened this issue Jan 29, 2024 · 8 comments

Comments

@ondrejmirtes
Copy link
Member

Feature request

https://phpstan.org/r/31b7e82b-cbdf-4241-903a-11c2c92bebaf

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

No response

@mad-briller
Copy link
Contributor

if the last element in the list is unset that would still preserve the list type is, is it worth taking that into account?

@ondrejmirtes
Copy link
Member Author

I don't think it remains a list. It also depends what happens when you append a new value after the unset using $a[] = 1.

@mad-briller
Copy link
Contributor

wow you are correct, you never stop learning weird aspects of php:

https://3v4l.org/leF25

@ondrejmirtes
Copy link
Member Author

Implemented phpstan/phpstan-src@aeadbe2

@staabm
Copy link
Contributor

staabm commented Feb 26, 2024

should we get the same error in this situation?

https://phpstan.org/r/d7ff4b4a-3972-4b58-ac4d-75baa331b03a

@staabm
Copy link
Contributor

staabm commented Feb 26, 2024

ohh I got it now. the actual errors happens when we write the "no longer list" back into a variable/property which expects a list.

the unset() itself is not the error. in my example it works by removing the list type from the variable involved
https://phpstan.org/r/a0182412-9c37-4195-9a96-4d280fa965e1

@ondrejmirtes
Copy link
Member Author

Yes 😊 btw you can get the error now with by-ref parameter: https://phpstan.org/r/af367901-7930-4a8b-9bcd-42156f7a2860

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants