diff --git a/lib/special_cases.php b/lib/special_cases.php index 417d4208..e423f9ad 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -455,7 +455,11 @@ function passthru(string $command, ?int &$result_code = null): void function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string { error_clear_last(); - $safeResult = \hash_file($algo, $filename, $binary, $options); + if (PHP_VERSION_ID >= 80500) { + $safeResult = \hash_file($algo, $filename, $binary, $options); + } else { + $safeResult = \hash_file($algo, $filename, $binary); + } if ($safeResult === false) { throw HashException::createFromPhpError(); } diff --git a/tests/SpecialCasesTest.php b/tests/SpecialCasesTest.php index 08f5e36c..6e9d61bf 100644 --- a/tests/SpecialCasesTest.php +++ b/tests/SpecialCasesTest.php @@ -58,6 +58,13 @@ public function testUnserializeOnInvalidData(): void \Safe\unserialize('invalid{'); } + public function testHashFileWithDefaultOptions(): void + { + $filename = __DIR__ . '/csv/test.csv'; + + $this->assertSame(\hash_file('sha256', $filename), \Safe\hash_file('sha256', $filename)); + } + /*public function testFgetcsvThrowsOnError() { if (($handle = \fopen(__DIR__."/csv/test3.csv", "r")) === false) {