Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

natcasesort does not create a list #10627

Closed
jorrit opened this issue Feb 23, 2024 · 3 comments
Closed

natcasesort does not create a list #10627

jorrit opened this issue Feb 23, 2024 · 3 comments

Comments

@jorrit
Copy link

jorrit commented Feb 23, 2024

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!

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@034f731

@jorrit
Copy link
Author

jorrit commented Feb 23, 2024

Thanks!

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants