php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71849 file_get_contents returns undocumented type
Submitted: 2016-03-18 00:13 UTC Modified: 2016-03-21 12:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:-1 (-100.0%)
From: hanskrentel at yahoo dot de Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hanskrentel at yahoo dot de
New email:
PHP Version: OS:

 

 [2016-03-18 00:13 UTC] hanskrentel at yahoo dot de
Description:
------------
I managed to make file_get_contents() return NULL which is undocumented (string and FALSE is documented).

Technically the case ("\0" as filename) triggers a warning so might not construe an error, but actually smells a lot like an error finally and should be FALSE.

This would also reduce handling return value logic.

So far it's merely unnoticed as undocumented, no idea if it's a technical difficulty to fix or just an oversight.

As this is NUL byte related this might make underlying problems visible.

As I'm undecided, I filed it as bug. It could be a documentation problem or security issue. Also a change request. As it could be all three, I filed it as bug which is undefined as well. HTH



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-18 00:18 UTC] hanskrentel at yahoo dot de
Example is <https://3v4l.org/33O0B>:

<?php

var_dump(file_get_contents("\0"));
 [2016-03-18 11:08 UTC] yohgaki@php.net
File path cannot contain NUL char.

	/* Parse arguments */
	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
		return;
	}

"p" is used and "\0" results in invalid path and zend_parse_parameters() fails. That's the reason why it returns NULL.

All other functions that expects file path returns NULL for "\0" due to zend_parse_parameters() failure.
 [2016-03-21 12:00 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2016-03-21 12:00 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See the note on <http://php.net/manual/en/functions.internal.php>:

> Note: If the parameters given to a function are not what it
> expects, such as passing an array where a string is expected,
> the return value of the function is undefined. In this case it
> will likely return NULL but this is just a convention, and
> cannot be relied upon.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 15:01:33 2024 UTC