|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-06-02 07:42 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 05:00:01 2025 UTC |
> So you prefer to be lied to? (/etc/passwd may very well exist?) for my application it don't exist and spit warnings to the errorlog is not helpful at all "Warning: This function returns FALSE for files inaccessible due to safe mode restrictions" - no matter if safe_mode now is gone - it has to return true in case i can access a file and in every other false what currently happens is that code which was not tested in a chroot or open_basedir environemnt spits the logfiles full with warning for file_exists('../path'); and enforces developers to spit the code full of @file_exists() while verybody knows the @ is typically the wrong solution