php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75473 Strange behavior of file_put_contents
Submitted: 2017-11-02 08:21 UTC Modified: 2017-11-03 14:48 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: namonexarap at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 7.1.11 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: namonexarap at gmail dot com
New email:
PHP Version: OS:

 

 [2017-11-02 08:21 UTC] namonexarap at gmail dot com
Description:
------------
See the test script.

Contents of file "my.txt" before running the test script
-------------------------
abc
-------------------------

Test script:
---------------
$data = file_get_contents("my.txt");
$data2 = $data.'Q';
file_put_contents("my.txt", $data2);

Expected result:
----------------
Contents of file "my.txt" after running the test script
-------------------------
abcQ
-------------------------

Actual result:
--------------
Contents of file "my.txt" after running the test script
-------------------------
abcQQ
-------------------------

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-02 08:38 UTC] samayo at 2itb dot com
This error seems to be working on 7.0 and 7.2 (not tested yet on 7.1)

Can you make sure you are not somehow calling the file twice? use microtime() or other better methods to check if this is a valid bug
 [2017-11-02 08:47 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-11-02 08:47 UTC] requinix@php.net
Pretty sure you're running it twice.
 [2017-11-03 09:55 UTC] namonexarap at gmail dot com
-Status: Feedback +Status: Closed
 [2017-11-03 09:55 UTC] namonexarap at gmail dot com
I found a problem in my program. This is not a PHP bug.
 [2017-11-03 10:18 UTC] spam2 at rhsoft dot net
what i don't understand is why you did
not run the pretend 2 liner you posted as reproducer isolated and if it's only to be sure it shows the problem which it didn't
 [2017-11-03 14:48 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC