Menu

← Back to arrayValues.*

Error Identifier: arrayValues.list

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);

/** @var list<string> $names */
$names = ['Alice', 'Bob', 'Charlie'];

$result = array_values($names);

Why is it reported? #

The array_values() function returns a list of all values in the array, re-indexed with consecutive integer keys starting from 0. PHPStan has determined that the argument is already a list (an array with consecutive integer keys starting from 0), so calling array_values() has no effect – the result will be identical to the input.

In the example above, $names is typed as list<string>, which already has sequential integer keys. Calling array_values() on it produces the same array.

How to fix it #

If the call is unnecessary, remove it:

 <?php declare(strict_types = 1);
 
 /** @var list<string> $names */
 $names = ['Alice', 'Bob', 'Charlie'];

-$result = array_values($names);
+$result = $names;

If you are calling array_values() to narrow the type from array to list, fix the type of the source variable instead so that it is already known to be a list.

How to ignore this error #

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

// @phpstan-ignore arrayValues.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: arrayValues.list

Rules that report this error #

  • PHPStan\Rules\Functions\ArrayValuesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.