From 885f28b1c482c54d17c77a761f28a6e36ea5ac49 Mon Sep 17 00:00:00 2001 From: Michael D Johnson Date: Mon, 9 Dec 2024 01:08:50 -0600 Subject: [PATCH] Force doubles to ints in group() PHP 8.4 deprecates the implicit conversion from doubles to ints when doing so would lose precision. However, disallowing doubles as array keys in Functional would be a BC break. --- src/Functional/Group.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Functional/Group.php b/src/Functional/Group.php index af2ed3a1..0a533d44 100644 --- a/src/Functional/Group.php +++ b/src/Functional/Group.php @@ -32,6 +32,11 @@ function group($collection, callable $callback) InvalidArgumentException::assertValidArrayKey($groupKey, __FUNCTION__); + // Avoid implicit precision-loss from doubles (which cannot be keys) + if (is_numeric($groupKey)) { + $groupKey = intval($groupKey); + } + if (!isset($groups[$groupKey])) { $groups[$groupKey] = []; }