|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78885 hash_file now shows a notice for directories and returns false
Submitted: 2019-11-29 10:57 UTC Modified: 2020-11-03 18:09 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: php-bugs at xpaw dot me Assigned:
Status: Open Package: Filesystem function related
PHP Version: 7.4.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php-bugs at xpaw dot me
New email:
PHP Version: OS:


 [2019-11-29 10:57 UTC] php-bugs at xpaw dot me

Until 7.4.0beta1, it returned string(32) "d41d8cd98f00b204e9800998ecf8427e" and since 7.4.0beta2 it displays a notice.

Notice: hash_file(): read of 8192 bytes failed with errno=21 Is a directory in /in/58RgW on line 3

On Windows there is no notice, and it only returns false. I'm only creating this issue as I don't see anything in upgrading notes, deprecated features or the changelog about it.

Test script:
var_dump( hash_file( 'md5', '/etc/' ) );


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-29 12:34 UTC]
-Package: hash +Package: Filesystem function related
 [2019-11-29 12:34 UTC]
This is not particularly related to hash_file(), but also affects
other filesystem functions, see <>.  IIRC,
that was a very deliberate change/fix.
 [2019-11-29 14:05 UTC]
-Assigned To: +Assigned To: nikic
 [2019-11-29 14:05 UTC]
Well, the behavioral change has been introduced with commit
1cbcf0f[1]; not sure whether this particular behavior has been
anticipated.  If so, PR #4474[2] appears to be superfluous now.

[1] <;a=commit;h=1cbcf0f4f1e9a14b3fc76f6d3e53b567a9464fd4>
[2] <>
 [2019-12-04 09:57 UTC]
This is intentional. PR #4474 is also still relevant, because it is a change specific to includes (not normal file reads).

UPGRADING currently only mentions this change for fread() and fwrite() in particular, but of course it also affects many, many other filesystem functions that read/write internally. I don't think we want to exhaustively list everything that might be affected.
 [2020-11-03 18:09 UTC]
-Status: Assigned +Status: Open -Type: Bug +Type: Documentation Problem -Assigned To: nikic +Assigned To:
 [2020-11-03 18:09 UTC]
Changing to doc problem for now (IIRC, there is at least one
duplicate of this ticket).
 [2023-01-28 09:25 UTC] alisawefguxbpn53 at gmail dot com
That was so amazing
 [2023-01-28 09:25 UTC] alisaurgbfnbxbpn53 at gmail dot com
That was so amazing. (
 [2023-06-02 06:44 UTC] mypennmedicine dot online at gmail dot com
Thank you. Your example didn't work for me but I managed to fix it, which was basically the same thing!

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 03:01:29 2024 UTC