php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76814 file_get_contents fail when maxlen is given null value
Submitted: 2018-08-30 08:00 UTC Modified: 2018-08-30 12:06 UTC
From: adrien dot blandin at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 7.1.21 OS: Debian
Private report: No CVE-ID: None
 [2018-08-30 08:00 UTC] adrien dot blandin at gmail dot com
Description:
------------
Signature of file_get_contents is ($filename, $use_include_path = false, $context = null, $offset = 0, $maxlen = null) so null is an allowed value for maxlen.

Yet, when I explicitly gave the default values in my call: file_get_contents($filename, false, null, 0, null), no content is found.

If I call the function with only the filename (so default values will be used too), content is found.

If I explicitly gave default values for all parameters except maxlen, content is found.

Test script:
---------------
echo 'default: ' . strlen(file_get_contents($filename)) . PHP_EOL;
echo 'without maxlen: ' . strlen(file_get_contents($filename, false, null, 0)) . PHP_EOL;
echo 'with maxlen: ' . strlen(file_get_contents($filename, false, null, 0, null)) . PHP_EOL;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-30 09:49 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-08-30 09:49 UTC] cmb@php.net
> Signature of file_get_contents is ($filename, $use_include_path
> = false, $context = null, $offset = 0, $maxlen = null) 

Where did you get this idea from?  The PHP manual[1] says the
signature is:

| string file_get_contents ( string $filename [, bool
| $use_include_path = FALSE [, resource $context [, int $offset = 0
| [, int $maxlen ]]]] )

So, the $maxlen parameter doesn't have a default; either pass an
argument, or not.

[1] <http://php.net/manual/en/function.file-get-contents.php>
 [2018-08-30 12:06 UTC] adrien dot blandin at gmail dot com
You're absolutely right. I get the signature from the auto-completion feature of my IDE (PHPStorm). It seems that they have an error and I didn't notice the difference with the manual.

All my apologies.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC