Repository navigation
Conversation
ndossche
left a comment
There was a problem hiding this comment.
This was also my first thought, but now playing with it I don't understand how the following makes sense:
<?php
function g() {
yield '1' => 'one';
yield '0' => 'zero';
}
function test(...$z) {
var_dump($z);
}
test(...['1'=>'one','0'=>'zero']);
test(...g());Yields:
array(2) {
[0]=>
string(3) "one"
[1]=>
string(4) "zero"
}
array(2) {
[0]=>
string(3) "one"
[1]=>
string(4) "zero"
}
So in both calls, the item with key '1' gets assigned to array index 0...
I see it is consistent between arrays and generators though, I just don't understand how this would make sense.
This question came to me after seeing the test which generates keys 100 until 102 but ends up with lower array indices
|
Not that I disagree that the behavior is weird, but array unpacking is likely factors more common than iterator unpacking, so IMO it makes more sense to adjust the less common case, at least without RFC or discussion. For example, changing how ints are interpreted could have subtle breaks, e.g. when using |
Closes GH-18581