vimeo/psalm

Psalm does not infer type in array_reduce()

Aberta

#6.370 aberto em 27 de ago. de 2021

 (6 comentários) (1 reação) (0 responsável)PHP (668 forks)batch import
Help wantedenhancement

Métricas do repositório

Stars
 (5.369 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

Given the following code:

/**
 * @param array<array{tags: string}> $a
 */
function test(array $a): string
{
    return array_reduce($a, function (string $carry, array $value) {
        return $carry . $value['tags'];
    }, '');
}

Psalm is unable to infer a type for $value in the callback function given to array_reduce():

https://psalm.dev/r/b9e02bcaaa

In this example, it should infer the type as array{tags: string}.

Can this be fixed?

Guia do colaborador