-
Notifications
You must be signed in to change notification settings - Fork 439
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
Add new ArrayUnpackingRule #856
Add new ArrayUnpackingRule #856
Conversation
Hi, I think we have to acknowledge multiple things here:
So I suggest this:
If you're unsure about bleeding edge, you can code the rule as normal and I'll configure it in a later commit :) Thank you! |
@canvural If you ever feel like finishing this, I'm looking forward to it! :) |
Yes, in my to-do list. I'll definitely do something about this when I have the time. Hope it's ok if this stays in draft. |
ddd20b4
to
95d480b
Compare
8adfab3
to
a582a5d
Compare
@ondrejmirtes It looks like there is already an error reported for all the things Also the invalid usage ( So the current rule in this PR seems sufficient? |
Yeah, but on PHP 8.0 PHPStan should complain about array with string keys being unpacked. Am I right? |
conf/config.level3.neon
Outdated
@@ -3,6 +3,7 @@ includes: | |||
|
|||
rules: | |||
- PHPStan\Rules\Arrays\ArrayDestructuringRule | |||
- PHPStan\Rules\Arrays\ArrayUnpackingRule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please adapt this similarly to this commit? 7627b52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Oh right, that's what this PR does. I need coffee. |
Hmm. Looks like no: https://3v4l.org/7lTWP Only for PHP < 8 |
a582a5d
to
9edb368
Compare
9edb368
to
0b2cc87
Compare
0b2cc87
to
4373952
Compare
Did a couple more adjustments: https://github.com/phpstan/phpstan-src/pull/856/commits |
Thank you! |
not sure why yet, but the test from this PR errors on macOS with php 8.1.2
|
Fixed: e131e35 |
Turns out there was a feature request for this :) phpstan/phpstan#5764 |
Before PHP 8.1, unpacking an array that contains string keys results in fatal error: https://3v4l.org/A4gqa
This PR adds a rule that can check this.
Not sure if this rule would be too annoying or not. All the
mixed
orarray-key
keyed arrays that being unpacked would error now. Which sounds in line with the runtime though.