php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49038 Wrong documentation for file_get_contents()
Submitted: 2009-07-23 18:59 UTC Modified: 2009-09-09 07:32 UTC
From: ryan at genius dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2009-07-23 18:59 UTC] ryan at genius dot com
Description:
------------
The documentation for file_get_contents() is wrong.  The default value 
of the maxlen param is stated to be -1 but, when looking at the C code, 
it is set to PHP_STREAM_COPY_ALL, not -1.  Passing -1 will trigger a 
warning and return false.

After looking at the C code, the default value is PHP_STREAM_COPY_ALL, 
not -1.

Reproduce code:
---------------
$fileContents = file_get_contents('file.txt', 0, null, -1, -1);

Expected result:
----------------
Get the entire file into $fileContents

Actual result:
--------------
Warning: "length must be greater than or equal to zero"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-09 07:31 UTC] svn@php.net
Automatic comment from SVN on behalf of torben
Revision: http://svn.php.net/viewvc/?view=revision&revision=288188
Log: Noted that the maxlen param is actually not -1 but is instead an
internal value (PHP_STREAM_COPY_ALL) and may not be directly specified
from within a script.
Addresses bug #49038 (although perhaps this is better fixed in the long
term by making file_get_contents() behave normally).
 [2009-09-09 07:32 UTC] torben@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jun 21 18:01:33 2025 UTC