php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66678 file_exists() no longer works as expected due to URL wrappers
Submitted: 2014-02-09 11:30 UTC Modified: 2014-02-10 12:08 UTC
From: hm2k@php.net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.4.25 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 4 = ?
Subscribe to this entry?

 
 [2014-02-09 11:30 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-09 17:22 UTC] bjori@php.net
-Status: Open +Status: Not a bug
 [2014-02-09 17:22 UTC] bjori@php.net
.
 [2014-02-10 10:48 UTC] hm2k@php.net
-Status: Not a bug +Status: Open -Type: Documentation Problem +Type: Bug
 [2014-02-10 10:48 UTC] hm2k@php.net
Unexpected behaviour is a bug.
 [2014-02-10 12:08 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-02-10 12:08 UTC] requinix@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC