Bug #76406 [Com]: file_exists() misleading error message and unexpected NULL return value

From: Date: Sat, 02 Jun 2018 08:28:33 +0000
Subject: Bug #76406 [Com]: file_exists() misleading error message and unexpected NULL return value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215471@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76406&edit=1

 ID:                 76406
 Comment by:         salsi at icosaedro dot it
 Reported by:        salsi at icosaedro dot it
 Summary:            file_exists() misleading error message and
                     unexpected NULL return value
 Status:             Open
 Type:               Bug
 Package:            Filesystem function related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Same exact behavior for these functions too, with same misleading error message, same undocumented
NULL return value and triggered E_WARNING:

is_writable() / is_writeable()
is_readable()
is_executable()
is_file()
is_dir()
is_link()

Again, in my opinion:

- These functions should do their business silently by testing their specific case on the submitted
string; no further diagnostic error should be emitted, as this could require a much more articulated
API for being useful to a running program. For example, programs may wish to test for the specific
structure of the path, URL, network resource, etc. or test for permissions, or test for remote
server accessibility, etc. and all this would requires specific API and feedback.

- Misleading error message still there.

- Unexpected undocumented NULL return value.


Previous Comments:
------------------------------------------------------------------------
[2018-06-02 07:42:16] salsi at icosaedro dot it

Description:
------------
If the string contains simply NUL, file_exists() gives a misleading error message and an unexpected
return value:

$ php -r "var_export(file_exists(\"\\x00\"));"
PHP Warning:  file_exists() expects parameter 1 to be a valid path, string given in Command line
code on line 1
NULL

Three issues here:

Issue 1. "file_exists() expects parameter 1 to be a valid path": should not complain about
invalid paths, as it is just its purpose to check for valid paths!

Issue 2. "string given": just the type of data the function is expecting to get; then
what's the issue?

Issue 3. NULL is an undocumented returned value; only FALSE and TRUE expected.

In my opinion:

- This function should always return only either TRUE or FALSE depending on the given argument: if
the argument can be successfully detected being a local file, a remote file or resource or whatever,
it should return TRUE, FALSE otherwise.

- No errors should ever be triggered because testing for valid paths is just the purpose of the
function, so basically this function should only tell if the argument is or is not a valid file,
resource, etc. An error could possibly be triggered if and only if the argument is something badly
wrong like an object or an array, that may indicate an internal program failure. Folks used to map
errors into exceptions are quite sensitive to this argument...

- If an error really worth to be reported, it should tell the argument cannot be parsed as a valid
file, URL or resource path or something like that. And in this case too, only either FALSE or TRUE
should be returned. Or, the manual page should be fixed accordingly.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76406&edit=1


Thread (8 messages)

« previous php.bugs (#215471) next »