Fix ArrayColumnFunctionReturnTypeExtension producing array key types#1033
Fix ArrayColumnFunctionReturnTypeExtension producing array key types#1033ondrejmirtes merged 2 commits intophpstan:masterfrom
Conversation
ondrejmirtes
left a comment
There was a problem hiding this comment.
Also - what happens when the column isn't a valid array key? Maybe an opportunity for a new rule later?
There was a problem hiding this comment.
I don't get it. Array gets cast to integer?
There was a problem hiding this comment.
See https://sandbox.onlinephpfunctions.com/code/381d0182b85cc698b02b18b82cd9dae0da3f7a00
I intentionally used 'foo' instead of 'type' in the array_column call in this example. So this seems to be the behaviour.
There was a problem hiding this comment.
Yes exactly. In PHP < 8, whenever a value cannot be used as an array key (either because it is an array, or the value is missing entirely), the next available integer array key is used (as if you'd do $arr[] = $value). In PHP >= 8, using an array value as key causes a fatal error, which of course is an opportunity for PHPStan to detect in the future.
There was a problem hiding this comment.
FYI I miss an if for this behaviour in this extension. Feel free to add in a future PR :)
e790289 to
06dcd54
Compare
|
Thank you! |
Fixes phpstan/phpstan#6682