From: Tim Düsterhus Date: Thu, 3 Aug 2023 12:03:02 +0000 (+0200) Subject: Accept `float`s in FileUtil::checkMemoryLimit() X-Git-Tag: 6.0.0_Alpha_8~15^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2ac108fb7fa4391a347edbc713d923aee3b68de6;p=GitHub%2FWoltLab%2FWCF.git 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. --- 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); }