|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74719 fopen() should accept NULL as context
Submitted: 2017-06-08 21:36 UTC Modified: -
From: love at sickpeople dot se Assigned:
Status: Closed Package: Streams related
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
7 + 32 = ?
Subscribe to this entry?

 [2017-06-08 21:36 UTC] love at sickpeople dot se
The only way to set *no context* to fopen() is to not set the 4th parameter.

This should be changed to accept NULL as 4th parameter, leading to *no context*.


 1) consistency. At least three related functions accepts NULL

 2) enables to set the context dynamically, eg avoiding if ($context) fopen (.., $context) else fopen (..)

 3) not a BC break, unless you include previously broken code

Test script:
file_put_contents ('/tmp/foo', 'bar', 0, NULL);

file_get_contents ('/tmp/foo', false, NULL);

file ('/tmp/foo', 0, NULL);

fopen ('/tmp/foo', 'r', false, NULL);

Expected result:
No warning

Actual result:
"PHP Warning:  fopen() expects parameter 4 to be resource, null given"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-08 21:41 UTC]
Same should be done for `fwrite` and the chunk size.
 [2018-01-17 11:47 UTC]
Automatic comment on behalf of
Log: Fixed bug #74719
 [2018-01-17 11:47 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 18:01:30 2024 UTC