From 5346491f3745d2d4c02be5ae6bbd0ae05afdaea2 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Fri, 4 Apr 2025 01:27:09 +0300 Subject: [PATCH] change array_is_list polyfill --- src/includes/common.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/includes/common.php b/src/includes/common.php index e6e7216..a4e50ad 100644 --- a/src/includes/common.php +++ b/src/includes/common.php @@ -198,16 +198,19 @@ function randomString(int $len = 16, string $chars = '0123456789abcdefghijklmnop return implode('', $a); } -// taken from symfony/polyfill-php81 (MIT License) if (!function_exists('array_is_list')) { + /** + * Checks whether a given array is a list + * @param array $array + * @return bool + */ + // https://www.php.net/manual/en/function.array-is-list.php#127044 function array_is_list(array $array): bool { - if ([] === $array || $array === array_values($array)) { - return true; - } - $nextKey = -1; + $i = -1; foreach ($array as $k => $v) { - if ($k !== ++$nextKey) { + ++$i; + if ($k !== $i) { return false; } }