Bug #76406 [Opn->Csd]: file_exists() misleading error message

From: Date: Tue, 12 Jan 2021 15:32:57 +0000
Subject: Bug #76406 [Opn->Csd]: file_exists() misleading error message
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231507@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 Updated by: cmb@php.net Reported by: salsi at icosaedro dot it Summary: file_exists() misleading error message -Status: Open +Status: Closed Type: Bug Package: Filesystem function related PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This is fixed as of PHP 8.0.1[1]. [1] <https://3v4l.org/oDuTv> Previous Comments: ------------------------------------------------------------------------ [2019-07-10 19:39:02] kainov dot oleg at gmail dot com I very agree with the OP - it's completely unexpected to get such a result (null and not helpful warning). > No, file_exists does not test valid paths. Ok, could you tell the community which function tests for valid paths? ------------------------------------------------------------------------ [2018-06-03 12:22:29] spam2 at rhsoft dot net > 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 ------------------------------------------------------------------------ [2018-06-02 22:47:28] cmb@php.net > […] and "a path" is a certain type of parameter that the engine > supports. To clarify: a path is a string which does not contain NUL bytes[1]. We may consider to introduce it as pseudo-type in the documentation. > […] it is not helpful to spit any warning for file_exists() and > friends for whatever reason (open_basedir as example) […] > […] i want a true/false So you prefer to be lied to? (/etc/passwd may very well exist…) Anyhow, changing the behavior of file_exists() and maybe other filesystem function would require the RFC process[2]. [1] <https://github.com/php/php-src/blob/php-7.2.6/README.PARAMETER_PARSING_API#L65-L66> [2] <https://wiki.php.net/rfc/howto> ------------------------------------------------------------------------ [2018-06-02 09:23:02] spam2 at rhsoft dot net don't change the fact that it is not helpful to spit any warning for file_exists() and friends for whatever reason (open_basedir as example) because sane environments are running with error_reporting E_ALL and display_errors off so you are forced in way too many situations typing @file_exists() while i don't care in the code why i can't access a given file, that's why i ask file_exists() and i want a true/false > An error could possibly be triggered if and only if > the argument is something badly wrong like an object or an array with strict_types you get a type error and then it's okay because you optet-in for that behavior and it's catchable ------------------------------------------------------------------------ [2018-06-02 09:16:49] requinix@php.net 1. No, file_exists does not test valid paths. It tests if a "file" exists. The presumption is that the path you are giving is valid, because if not then it couldn't possibly exist. And no filesystem I've heard of allows NULs. 2. "expects parameter %d to be a valid path, string given" is a bit unusual. The message says that because the check is done during the parameter check phase that every function uses, and "a path" is a certain type of parameter that the engine supports. That also means altering the message for this particular case may not be easy. 3. http://php.net/manual/en/functions.internal.php ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=76406 -- Edit this bug report at https://bugs.php.net/bug.php?id=76406&edit=1

« previous php.bugs (#231507) next »