|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75836 fwrite() should accept null for chunk size
Submitted: 2018-01-17 16:48 UTC Modified: 2021-07-27 11:38 UTC
From: Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 7.2.1 OS:
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:
New email:
PHP Version: OS:


 [2018-01-17 16:48 UTC]
This is a follow-up of bug #74719, which didn't address `fwrite()`.

See for an example where this is annoying.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-17 18:57 UTC]
Additional filesystem functions that have the same or similar problems:

Optional $context arg emits warning when explicit NULL is passed to all of: copy(), mkdir(), rename(), rmdir(), unlink()

fgetss(), fgets() - NULL passed to $length is cast to int(0), emits warning
file_get_contents() - NULL passed to $maxlen results in empty string returned
 [2018-01-18 17:13 UTC]
> fwrite() should accept null for chunk size

That would constitute a BC break, though.

> for an example where this is annoying.

  $written = @\fwrite($stream, $data, $chunkSize ?: $length);
 [2018-01-18 20:09 UTC]
How would that be a BC break?
 [2018-01-18 23:50 UTC]
> How would that be a BC break?

Presently, passing NULL as third parameter to fwrite() causes
nothing to be written.  If I understand you correctly, you want
that to change so that the whole $string is written instead.
 [2018-01-19 08:04 UTC] spam2 at rhsoft dot net
bad idea - the param is defined as int which means in weak mode it will be casted and NULL becomes 0 (what you don't want) while with strict_types it is a fatal error to pass NULL - that is the expected behavior from each and every function and should stay consistent
 [2021-07-27 11:38 UTC]
-Status: Open +Status: Closed -Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: cmb
 [2021-07-27 11:38 UTC]
All mentioned parameters are nullable as of PHP 8.0.0.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 09:01:30 2024 UTC