Skip to content

usort() removes variable type information when invoked on a key with an associative array #11322

@gmta

Description

@gmta

Bug report

Playground example:
https://phpstan.org/r/0a8ba5a2-1dc9-4c98-9146-3fe09acbae2f

This seems to be the minimal case - using an array list or invoking usort() on an associative array directly does not exhibit this behavior. The variable type is replaced by *NEVER* potentially causing issues further down the line. I wasn't able to produce an example that triggers an issue with the *NEVER* type however.

Using uasort() instead of usort() does not trigger this issue.

Code snippet that reproduces the problem

https://phpstan.org/r/0a8ba5a2-1dc9-4c98-9146-3fe09acbae2f

Expected output

The expected new type should be array{map: array<int, 'b'>}

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