|  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: 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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


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

Test script:

$files = array();
$files[] = php_ini_loaded_file(); //a file that always exists
$files[] = ''; //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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-09 17:22 UTC]
-Status: Open +Status: Not a bug
 [2014-02-09 17:22 UTC]
 [2014-02-10 10:48 UTC]
-Status: Not a bug +Status: Open -Type: Documentation Problem +Type: Bug
 [2014-02-10 10:48 UTC]
Unexpected behaviour is a bug.
 [2014-02-10 12:08 UTC]
-Status: Open +Status: Not a bug
 [2014-02-10 12:08 UTC]
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()
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jan 17 01:01:23 2021 UTC