# Behaviour of put_file_contents()?

- Thread: https://externals.io/message/2917
- Original archive: https://news-web.php.net/php.internals/2917
- Started by Paul Hudson on 2003-06-28T00:51:55+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #2917 — Paul Hudson — 2003-06-28T00:51:55+00:00

URL: https://externals.io/message/2917#2917

All,

The manual currently doesn't specify what the function file_put_contents 
returns beyond just "int".  The code prototype says string, and the function 
appears to return a boolean rather than any integer (at least in the latest 
CVS).  Which of the three should it be?

I was /expecting/ it to return an integer of the number of bytes written, as 
in the included (albeit very simplistic!) patch.


Paul
--

[paul@alice standard]$ diff -u file.c.old file.c
--- file.c.old  2003-06-28 01:13:19.000000000 +0100
+++ file.c      2003-06-28 01:13:29.000000000 +0100
@@ -474,7 +474,7 @@
 }
 /* }}} */

-/* {{{ proto string file_put_contents(string file, string data[, int flags[, 
resource context]])
+/* {{{ proto int file_put_contents(string file, string data[, int flags[, 
resource context]])
    Write/Create a file with contents data */
 PHP_FUNCTION(file_put_contents)
 {
@@ -506,7 +506,7 @@
        }
        php_stream_close(stream);

-       RETURN_TRUE;
+       RETURN_LONG(numbytes);
 }
 /* }}} */

---

## #2927 — Derick Rethans — 2003-06-28T08:18:48+00:00

URL: https://externals.io/message/2917#2927 · In reply to: #2917

> All,
> 
> The manual currently doesn't specify what the function file_put_contents 
> returns beyond just "int".  The code prototype says string, and the function 
> appears to return a boolean rather than any integer (at least in the latest 
> CVS).  Which of the three should it be?
> 
> I was /expecting/ it to return an integer of the number of bytes written, as 
> in the included (albeit very simplistic!) patch.

Applied, thanks!

Derick

-- 
"Interpreting what the GPL actually means is a job best left to those
                    that read the future by examining animal entrails."
-------------------------------------------------------------------------
 Derick Rethans                                 http://derickrethans.nl/ 
 International PHP Magazine                          http://php-mag.net/
