-
-
Notifications
You must be signed in to change notification settings - Fork 947
Array shapes with array_reverse wrong return type #11549
Copy link
Copy link
Closed
Labels
Milestone
Description
Bug report
Having a code:
<?php declare(strict_types = 1);
/**
* @param array{0: string, 1?: string} $a
* @return array{0: string, 1?: string}
*/
function rrr(array $a): array
{
return array_reverse($a);
}it results with an error:
Function rrr() should return array{0: string, 1?: string} but returns array{0?: string, 1: string}.
which is not true, having array of 1 or 2 strings revered, it will always results with an array of 1 or 2 strings.
Code snippet that reproduces the problem
Expected output
No issue reported.
Did PHPStan help you today? Did it make you happy in any way?
No response
Reactions are currently unavailable