Skip to content

Commit

Permalink
Force doubles to ints in group()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
redbeardcreator committed Dec 9, 2024
1 parent bdfef5f commit 885f28b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Functional/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [];
}
Expand Down

0 comments on commit 885f28b

Please sign in to comment.