From dd5d6a34060b5c2c8a8eb98d8bda232b319330f4 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 23 Oct 2025 11:19:29 +0200 Subject: [PATCH 1/3] chore: Add PHP 8.5 to CI matrix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aed4718..aaf8e27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] os: [ubuntu-latest] runs-on: ${{ matrix.os }} From 8838f1c7581a70dfc4d93f89ad35f1611dd2c018 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 23 Oct 2025 18:40:24 +0200 Subject: [PATCH 2/3] fix: Introduce PHP 8.5 compatibility for hashCode function PHP 8.5 introduced stricter float-to-int casting that throws an error when a float value is not representable as an integer. The hashCode function's bit shifting operations could produce values exceeding PHP's integer range, causing automatic conversion to float and subsequent casting errors. This fix applies bitwise AND with 0xFFFFFFFF to keep values within 32-bit range and properly converts from unsigned to signed 32-bit integers, preventing float conversion while maintaining consistent hash values. Fixes #39 --- src/Util.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Util.php b/src/Util.php index b4220e9..ca69cb9 100644 --- a/src/Util.php +++ b/src/Util.php @@ -10,7 +10,13 @@ function hashCode(string $s): int } for ($i = 0; $i < strlen($s); $i++) { $chr = ord($s[$i]); - $hash = (int) (($hash << 5) - $hash + $chr); + // Use bitwise operations to ensure we stay within 32-bit signed integer range + // This prevents float conversion and maintains compatibility with PHP 8.5+ + $hash = ((($hash << 5) - $hash) + $chr) & 0xFFFFFFFF; + // Convert from unsigned 32-bit to signed 32-bit + if ($hash > 0x7FFFFFFF) { + $hash = $hash - 0x100000000; + } } return $hash; } From 655b22d275e556cda7a60012ab150d833f5a425f Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Tue, 28 Oct 2025 19:36:52 +0100 Subject: [PATCH 3/3] Update Util.php Co-authored-by: Peter Zhu <7332407+zhukaihan@users.noreply.github.com> --- src/Util.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Util.php b/src/Util.php index ca69cb9..0c4cf31 100644 --- a/src/Util.php +++ b/src/Util.php @@ -12,11 +12,7 @@ function hashCode(string $s): int $chr = ord($s[$i]); // Use bitwise operations to ensure we stay within 32-bit signed integer range // This prevents float conversion and maintains compatibility with PHP 8.5+ - $hash = ((($hash << 5) - $hash) + $chr) & 0xFFFFFFFF; - // Convert from unsigned 32-bit to signed 32-bit - if ($hash > 0x7FFFFFFF) { - $hash = $hash - 0x100000000; - } + $hash = ((($hash << 5) - $hash) + $chr) & 0x7FFFFFFF; } return $hash; }