Doc #76132 [Fbk->Csd]: Documentation lacks a warning about file_put_contents()
| From: | briethings at gmail dot com | Date: | Thu, 22 Mar 2018 02:59:10 +0000 |
| Subject: | Doc #76132 [Fbk->Csd]: Documentation lacks a warning about file_put_contents() | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15555@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76132&edit=1
ID: 76132
User updated by: briethings at gmail dot com
Reported by: briethings at gmail dot com
Summary: Documentation lacks a warning about
file_put_contents()
-Status: Feedback
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: any
PHP Version: 5.6.34
Block user comment: N
Private report: N
New Comment:
Sorry, you're totally right!
However I had error_reporting set to E-ALL, but I fell into a stupid but interesting pitfall (so
I'll report it to user-notes instead of bug!).
Here it is: the $filename arg was coded as $path.$file, with say $path = 'path/to' and
$file = 'file.txt'.
You see that $path lacks its ending "/", so the resulting full path was
'path/tofile.txt': so file_put_contents() didn't fail but created the
'tofile.txt' in the *parent* directory of the one where I expected it, making me believe
that nothing had happened!
Again, sorry for the false alert, and thanks for your vigilance.
Previous Comments:
------------------------------------------------------------------------
[2018-03-22 01:58:25] requinix@php.net
You sure? Because on Windows I see
> Warning: file_put_contents(...): failed to open stream: No such file or directory
Maybe you have warnings hidden? Check your display_errors, error_log, and error_reporting settings.
------------------------------------------------------------------------
[2018-03-22 00:11:43] briethings at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.file-put-contents
---
Documentation doesn't mention that, if the directory specified in $filename doesn't exist,
file_put_contents() *silently* fails, with not even a notice.
This can lead to situations where it may take time before realizing there is a simple type error!
So IMO, at least this should be mentioned, or a notice should be thrown.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76132&edit=1