Bug #66678 [Opn->Nab]: file_exists() no longer works as expected due to URL wrappers

From: Date: Mon, 10 Feb 2014 12:08:41 +0000
Subject: Bug #66678 [Opn->Nab]: file_exists() no longer works as expected due to URL wrappers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184236@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66678&edit=1 ID: 66678 Updated by: requinix@php.net Reported by: hm2k@php.net Summary: file_exists() no longer works as expected due to URL wrappers -Status: Open +Status: Not a bug Type: Bug Package: Filesystem function related PHP Version: 5.4.25 Block user comment: N Private report: N New Comment: Unexpected behavior isn't a bug when you're the only one not expecting it. file_exists() has nothing to do with checking if a "file" is local or remote. All it tries to do is check whether something exists. What you want is stream_is_local() http://www.php.net/stream-is-local Previous Comments: ------------------------------------------------------------------------ [2014-02-10 10:48:26] hm2k@php.net Unexpected behaviour is a bug. ------------------------------------------------------------------------ [2014-02-09 17:22:15] bjori@php.net . ------------------------------------------------------------------------ [2014-02-09 11:30:04] hm2k@php.net Description: ------------ For Context: "Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to Supported Protocols and Wrappers to determine which wrappers support stat() family of functionality." You'll note that file_exists() is listed as a "file system function", yet it no longer behaves as expected due to the URL wrappers. This means you can no longer use the file_exists() to ensure that a file does exist on the local file system, as it may equally exist (or not exist) on a remote URL. I therefore propose that file_exists() be renamed to schlesingers_file_exists() as at least this would make sense. --- From manual page: http://www.php.net/function.file-exists --- Test script: --------------- <pre> <?php $files = array(); $files[] = php_ini_loaded_file(); //a file that always exists $files[] = 'ftp://ftp.gnu.org/'; //a file that is a URL foreach ($files as $file) { if (file_exists($file)) { echo "'$file' file exists\n"; } } ?> Expected result: ---------------- You would expect file_exists() to only be true if the file exists on the local file system. Actual result: -------------- file_exists() will return true if the file does (or does not) exist on a remote URL. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66678&edit=1

« previous php.bugs (#184236) next »