Fix hash_file options on PHP before 8.5 - #757
Closed
lcmialichi wants to merge 1 commit into
Closed
lcmialichi wants to merge 1 commit into
lcmialichi wants to merge 1 commit into
Conversation
lcmialichi
commented
Oct 2, 2026
lcmialichi
left a comment
Author
There was a problem hiding this comment.
Correction after validation: PHP.Watch documents the fourth hash_file() $options parameter as added in PHP 8.1. The official PHP 8.1.34 image exposes four parameters and accepts the call; PIE 1.5.1 also installed and loaded the extension end-to-end under PHP 8.1.34. The earlier failure was limited to Ubuntu's 8.1.2-1ubuntu2.26 build, which reports only three parameters. This PR's PHP_VERSION_ID < 8.5 branch would disable documented options on PHP 8.1–8.4 and is not the right fix. I recommend closing this PR; if the Ubuntu-specific mismatch needs support, investigate feature detection separately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Safe\hash_file()always forwards its optional$optionsargument to nativehash_file(). The native fourth argument is only available starting in PHP 8.5, so on PHP 8.1-8.4 the wrapper throwsArgumentCountErroreven when callers omit$options(the default[]is still forwarded).This changes the wrapper to pass
$optionsonly on PHP 8.5+, while preserving the existing false-result handling andHashExceptionbehavior. It also adds a regression test for the default-argument call.Verification
Safe\hash_file('sha256', $file)matches native output.seedoptions match native output.