Bug #76406 [NEW]: file_exists() misleading error message and unexpected NULL return value
| From: | salsi at icosaedro dot it | Date: | Sat, 02 Jun 2018 07:42:22 +0000 |
| Subject: | Bug #76406 [NEW]: file_exists() misleading error message and unexpected NULL return value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215470@lists.php.net to get a copy of this message | ||
From: salsi at icosaedro dot it
Operating system:
PHP version: Irrelevant
Package: Filesystem function related
Bug Type: Bug
Bug description:file_exists() misleading error message and unexpected NULL return value
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 bug report at https://bugs.php.net/bug.php?id=76406&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76406&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76406&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76406&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76406&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76406&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76406&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76406&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76406&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76406&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76406&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76406&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76406&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76406&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76406&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76406&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76406&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76406&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76406&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76406&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76406&r=mysqlcfg