diff --git a/src/Assert.php b/src/Assert.php index db1f3a5..3c4b933 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1828,17 +1828,24 @@ public static function isList($array, $message = '') ); } - if ($array === \array_values($array)) { - return; - } - - $nextKey = -1; - foreach ($array as $k => $v) { - if ($k !== ++$nextKey) { + if (\function_exists('array_is_list')) { + if (!\array_is_list($array)) { static::reportInvalidArgument( $message ?: 'Expected list - non-associative array.' ); } + return; + } + + if ([] === $array) { + return; + } + + $keys = array_keys($array); + if (array_keys($keys) !== $keys) { + static::reportInvalidArgument( + $message ?: 'Expected list - non-associative array.' + ); } }