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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hm2k@php.net
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 05:01:28 2024 UTC