Skip to content

natcasesort does not create a list #10627

@jorrit

Description

@jorrit

Bug report

Since release 1.10.59 the following code is considered erroneous (in bleeding edge mode):

$list = ['A', 'C', 'B'];
natcasesort($list);
array_values($list);

The error is:

Parameter #1 $array (array{'A', 'C', 'B'}) of array_values is already a list, call has no effect.

However, the keys of $list are [0, 2, 1] after the call to natcasesort() so array_values does have an effect.

Code snippet that reproduces the problem

https://phpstan.org/r/ca0016cb-97aa-4a95-9bd0-6aced40c30f2

Expected output

No errors should be reported, as array_values() can be useful after natcasesort.

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

PHPStan found several calls to array_values() that were indeed unnecessary. Thanks!

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