php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65089 Please clarify how to use fopen modes together
Submitted: 2013-06-21 16:41 UTC Modified: 2013-06-21 16:45 UTC
From: truenrush at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.5.0 OS: Any
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: truenrush at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-21 16:41 UTC] truenrush at gmail dot com
Description:
------------
I am confused, that there are not examples how to use read-write mode (w+) with 
binary modificator (b). Should it be "w+b"? Or "wb+"? or "bw+"? 

I've spend some time to understand how it works (i can test only on linux, so i am 
not sure in test results about "t" mode, but read-write operations should be done 
same on the any OS).

Please, explain on http://www.php.net/manual/en/function.fopen.php page, how can i 
use modes altogether, which ways are acceptable, thanks!

Test script:
---------------
// In this example i use "t" modificator, but it does not matter exactly
// w+t
$h = fopen('test.file', 'w+t');
fwrite($h, "test \ntest \ntest \n");
fseek($h, 0);
$data = fread($h, filesize('test.file'));
var_dump($data); // data is written and read normally
fclose($h);

// wt+, same result
$h = fopen('test.file', 'wt+');
fwrite($h, "test \ntest \ntest \n");
fseek($h, 0);
$data = fread($h, filesize('test.file'));
var_dump($data); // data is written and read normally, 
fclose($h);

Expected result:
----------------
It is decribed in documentation:

1) how it is possible to combine modes ("t" and "b" in addition to usual ones), 
should it be w+b, wb+, etc. What is correct syntax?

2) is it enough to use "t" mode only when reading under windows, or i should write 
file first of all (to replace all \n with \r\n), and then read it normally? It is 
not clear



Actual result:
--------------
Documentation description exists, but is not clear.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-21 16:42 UTC] truenrush at gmail dot com
-Summary: Please clarify how to use modes together +Summary: Please clarify how to use fopen modes together
 [2013-06-21 16:42 UTC] truenrush at gmail dot com
*Added fopen in the header to clarify which modes are confusing*
 [2013-06-21 16:45 UTC] truenrush at gmail dot com
-Status: Open +Status: Closed
 [2013-06-21 16:45 UTC] truenrush at gmail dot com
I will read docs carefully. I will read docs carefully. I will read docs 
carefully.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 20:00:02 2026 UTC