Skip to content

Array shapes with array_reverse wrong return type #11549

@kubawerlos

Description

@kubawerlos

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

https://phpstan.org/r/13270977-2e74-413f-9d7f-904dd76b9096

Expected output

No issue reported.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions