php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: love at sickpeople dot se
New email:
PHP Version: OS:

 

 [2017-06-08 21:36 UTC] love at sickpeople dot se
Description:
------------
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*.

Why?

 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"

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-08 21:41 UTC] kelunik@php.net
Same should be done for `fwrite` and the chunk size.
 [2018-01-17 11:47 UTC] nikic@php.net
Automatic comment on behalf of alexander@holman.org.uk
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a01de10b075de9558dfe27535e601c7c4c0c819e
Log: Fixed bug #74719
 [2018-01-17 11:47 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC