Bug #72983 [Nab]: file_put_contents does not overwrite if file exists

From: Date: Mon, 05 Sep 2016 05:36:39 +0000
Subject: Bug #72983 [Nab]: file_put_contents does not overwrite if file exists
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203797@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72983&edit=1

 ID:                 72983
 Updated by:         requinix@php.net
 Reported by:        jim dot michaels at Jesusnjim dot com
 Summary:            file_put_contents does not overwrite if file exists
 Status:             Not a bug
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   vista x32 amd
 PHP Version:        7.1.0beta3
 Assigned To:        cmb
-Block user comment: No
+Block user comment: Yes
 Private report:     N

 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------
[2016-09-05 05:30:07] jim dot michaels at Jesusnjim dot com

why does it seem file_put_contents again does not touch my files? file dates have not changed and
menu has not been inserted.

yet when I test locally it "works".. so it works sometimes and fails most of the time.
does file_put_contents like \ or / in its filepaths, absolute or relative or both?

------------------------------------------------------------------------
[2016-09-05 04:00:03] requinix@php.net

Given that you were able to run PHP just fine earlier, what changed? Are you sure you downloaded the
x86 build?

------------------------------------------------------------------------
[2016-09-05 03:21:21] jmichae3 at yahoo dot com

c:\>php menu7a.php
This version of c:\php71nts\php.exe is not compatible with the version of Windows you're
running. Check your computer's system information to see whether y
ou need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software
publisher.

c:\>

using vista 32, please backrev your compiler.

------------------------------------------------------------------------
[2016-09-04 10:16:37] cmb@php.net

> No bug. There is exactly one bug in this bug report and it is
> with your own code. Not with PHP. Not with PCRE.

That.

Suggestion: use str_replace() instead of preg_replace() in this
case:

  str_replace('/', '\\', $a);

------------------------------------------------------------------------
[2016-09-04 02:50:58] requinix@php.net

Actually you're the one missing the point. There is no bug. The problem is that your code was
not doing what you thought it was doing. It has nothing to do with files and everything to do with
you not understanding what was happening with backslashes.

https://3v4l.org/C361B

See how the output in both versions is the same? Writing to the file worked fine, but you were
writing the same value both times.

"that 8 \\\\\\\\\ for 1 \ character is a bell-ringer for a problem that needs fixing"

I'm not sure how you managed to misunderstand my comment, but between PHP and PCRE you need two
levels of escaping. That's 4x the number of backslashes required. One in the output = 4 in the
string, two in the output = 8 in the string.

Side note: here's what happens when you use 1-8 backslashes in PHP and PHP+PCRE: https://3v4l.org/Sjn85

"//bug in PCRE doesn't replace / with 2 \ chars"
No bug. There is exactly one bug in this bug report and it is with your own code. Not with PHP. Not
with PCRE.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=72983


--
Edit this bug report at https://bugs.php.net/bug.php?id=72983&edit=1


Thread (15 messages)

« previous php.bugs (#203797) next »