Behaviour of put_file_contents()?

php.internals

Paul Hudson

23 years ago
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); } /* }}} */

Derick Rethans

23 years ago
On Sat, 28 Jun 2003, Paul Hudson wrote:
> 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/ -------------------------------------------------------------------------