Bug #70814 [Opn->Nab]: fopen('file', 'w+') breaks subsequent file_get_contents calls
Edit report at https://bugs.php.net/bug.php?id=70814&edit=1
ID: 70814
Updated by: requinix@php.net
Reported by: pedronaroga at gmail dot com
Summary: fopen('file', 'w+') breaks subsequent
file_get_contents calls
-Status: Open
+Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: Ubuntu 15.10
PHP Version: 7.0.0RC6
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
w+ will truncate the file.
Previous Comments:
------------------------------------------------------------------------
[2015-10-29 17:56:55] pedronaroga at gmail dot com
Description:
------------
Using the following snippet, I get the correct response:
var_dump(file_get_contents('my_local_file')); //Prints file contents
fopen('my_local_file', 'r+');
var_dump(file_get_contents('my_local_file')); //Prints file contents again
However, changing the mode in fopen to 'w+', causes weird behaviour:
var_dump(file_get_contents('my_local_file')); //Prints file contents
fopen('my_local_file', 'w+');
var_dump(file_get_contents('my_local_file')); //Prints an empty string
Error is reproductible in PHP 5.6.
Test script:
---------------
<?php
var_dump(file_get_contents('my_local_file')); //Prints file contents
fopen('my_local_file', 'w+');
var_dump(file_get_contents('my_local_file')); //Prints an empty string
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70814&edit=1
Thread (2 messages)