-
Notifications
You must be signed in to change notification settings - Fork 680
Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists #8395
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
right now, sealed arrays can only be created by explicitly creating an array in php. The sealed flag is used for several things (like being sure of how many elements there is in an array or checking if the array can be inferred to be empty, things like that). If you want to be able to document a There will be a bunch of things like that to handle that were not previously implemented because the sealed flag couldn't be used directly by people. |
I think list{} is ultra confusing, since a list currently is a 0-monotonous index array. |
We have a is_list property in TKeyedArray that will change a standard keyed array like |
Ah that makes sense, I suppose it would be nice to have an This PR should be now good to merge, the phpcs comments can be removed once @ondrejmirtes merges phpstan/phpdoc-parser#161 and tags, which adds basic strict-array, strict-list and list syntax support to phpstan and phpcs, and @romm merges CuyZ/Valinor#246 so at least |
… we can add valinor to the psalm docs :)
Thanks a lot again! |
This is very useful feature. Can it be added to 4.x branch? |
Sorry, the |
@danog I tried, but it is the Symfony plugin that depends on V4. Never mind, I will see what I can do. Thank you for this awesome feature anyway. |
It makes sense that Symfony still depends on Psalm 4 given the release is yet to come! One of our task after releasing will be to make sure there are no big plugins left behind for too long :) |
This PR introduces new syntax to define list-like keyed arrays:
list{}
which replaces the previously undocumented (and frankly confusing)array{int, string}
.Also introducing syntax for
callable-list{}
.Finally, introducing
strict-*{}
for sealed variants of array types.