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: 2020-12-12 13:32 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: testreal at i dot ua Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 7.1.11 OS: Windows 7
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: testreal at i dot ua
New email:
PHP Version: OS:

 

 [2017-11-02 08:21 UTC] testreal at i dot ua
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
 [2020-12-12 13:32 UTC] testreal at i dot ua
-: namonexarap at gmail dot com +: testreal at i dot ua
 [2020-12-12 13:32 UTC] testreal at i dot ua
I change my email
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 18:01:31 2024 UTC