From 2ac108fb7fa4391a347edbc713d923aee3b68de6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 3 Aug 2023 14:03:02 +0200 Subject: [PATCH] Accept `float`s in FileUtil::checkMemoryLimit() While a decimal amount of bytes is not something that exists, it's a common pattern to approximate the required memory usage of an image operation with the factor `2.1`, possibly resulting in decimal places. PHP 8.1 emits a warning if an implicit cast from non-integer float to int happens. As the input is only used within an inequality expression and not further processed it is safe to accept arbitrary floats and preferable to slapping explicit casts onto everything. --- wcfsetup/install/files/lib/util/FileUtil.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/util/FileUtil.class.php b/wcfsetup/install/files/lib/util/FileUtil.class.php index 5e7293d66a..3844c670d5 100644 --- a/wcfsetup/install/files/lib/util/FileUtil.class.php +++ b/wcfsetup/install/files/lib/util/FileUtil.class.php @@ -547,7 +547,7 @@ final class FileUtil /** * Returns true if the given amount of memory is available. */ - public static function checkMemoryLimit(int $neededMemory): bool + public static function checkMemoryLimit(int|float $neededMemory): bool { return self::getMemoryLimit() == -1 || self::getMemoryLimit() > (\memory_get_usage() + $neededMemory); } -- 2.20.1