Menu

Error Identifier: sortArray.list

← Back to sortArray.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

/** @param list<string> $list */
function doFoo(array $list): void
{
	ksort($list);
}

Why is it reported? #

ksort() sorts an array by its keys. A list is an array whose keys are consecutive integers starting from 0, so its keys are already in ascending order. With the default SORT_REGULAR flag (or SORT_NUMERIC), sorting those keys leaves the array unchanged, so the call has no effect. This usually indicates a logic error or leftover code.

This check is part of PHPStan’s bleeding edge and runs at rule level 5.

How to fix it #

Remove the pointless sort call:

 /** @param list<string> $list */
 function doFoo(array $list): void
 {
-	ksort($list);
 }

If you meant to sort by value instead of by key, use sort():

 /** @param list<string> $list */
 function doFoo(array $list): void
 {
-	ksort($list);
+	sort($list);
 }

If the list type comes from a PHPDoc that you believe is inaccurate, you can turn off this check by setting treatPhpDocTypesAsCertain: false.

How to ignore this error #

You can use the identifier sortArray.list to ignore this error using a comment:

// @phpstan-ignore sortArray.list
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: sortArray.list

Rules that report this error #

  • PHPStan\Rules\Functions\SortWithoutEffectRule [1]
Theme
A
© 2026 PHPStan s.r.o.