array<array-key, mixed> not compatible with array<int|string, mixed> why? #10617
-
why is this marked as error? is not array-key equal to int|string? Source code/**
* @return array<array-key, mixed>
*/
function returnArrayKeyMixed(): array
{
return ['key' => 'value', 1];
}
/**
* @param array<int|string, mixed> $array
*/
function acceptIntStringMixed(array $array): void {}
acceptIntStringMixed(returnArrayKeyMixed()); PHPStan error
Versions
PHPStan config
Valid variation 1switching array-key to int|string on return and array-key on input passes /**
* @return array<int|string, mixed>
*/
function returnIntStringMixed(): array
{
return ['key' => 'value', 1];
}
/**
* @param array<array-key, mixed> $array
*/
function acceptArrayKeyMixed(array $array): void {}
acceptArrayKeyMixed(returnIntStringMixed()); Valid variation 2switching array<array-key, *> to *[] on return passes /**
* @return mixed[]
*/
function returnArrayOfMixed(): array
{
return ['key' => 'value', 1];
}
/**
* @param array<array-key, mixed> $array
*/
function acceptArrayKeyMixed(array $array): void {}
acceptArrayKeyMixed(returnArrayOfMixed()); |
Beta Was this translation helpful? Give feedback.
Answered by
ondrejmirtes
Feb 23, 2024
Replies: 2 comments 1 reply
-
Yes, it should be interchangeable. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tomchochola
-
issue opened: #10624 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it should be interchangeable.