Skip to content

array_count_values returned value is not taking care of the key-type #13816

@niconoe-

Description

@niconoe-

Bug report

Hello !

When calling array_count_values, PHPStan's dumped type for the returned value is array<int<…>>, ignoring the definition of the type of the keys for such array.

When working with a list of integers or a list of strings (or Stringable objects), it should return respectively array<int, int<…>> or array<string, int<…>>, as the values of the given array as argument become (after cast into array-key pseudotype) the keys of the returned array by array_count_values.
When working with a list of mixed integers and string (or Stringable objects), it could be left as is, or explicitly be array<array-key, int<…>>.

Thanks a lot!

Code snippet that reproduces the problem

https://phpstan.org/r/fc787ecb-635e-4655-bb3e-309e47db44f4

Expected output

Expected errors displayed by the Playground:

11 Dumped type: array<string, int<1, max>>

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

I'm still using PHPStan everyday since a pretty high number of years now, and it's still awesome. Thank you very much for this incredible work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions