Skip to content

usort changes type of passed variable, phpstan not picking it up #3312

@d-claassen

Description

@d-claassen

Bug report

usort accepts a passed-by-reference array of array<array-key, T> as first argument, but will always transform that argument into array<int, T>. This is also noted in the php docs:

Note: This function assigns new keys to the elements in array. It will remove any existing keys that may have been assigned, rather than just reordering the keys.

So when giving usort an array of array<string, T> the passed array becomes array<int, T>. PHPStan however does not pick this up. I looked at updating the functionMap.php file, but I did not see how this can be documented in the current format. If I missed something I'd be happy to provide a pull request with an update to it!

Code snippet that reproduces the problem

The snippet that reproduces can be found here:
https://phpstan.org/r/cd33a591-5f93-4df3-b878-49af85ef487e

I've also confirmed the behavior as described in the php docs with the same code in this 3v4l.org test.

Expected output

I would've expected PHPStan not to return an error. Both Psalm and Phan do not return any error about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions