|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12033 file_exists doesn't work properly with variables
Submitted: 2001-07-11 01:00 UTC Modified: 2010-12-20 15:16 UTC
From: ddruff at gemini1consulting dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.5 OS: Win 95
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:
Solve the problem:
49 - 34 = ?
Subscribe to this entry?

 [2001-07-11 01:00 UTC] ddruff at gemini1consulting dot com
The following won't work in Win95:

if(file_exists($path)) {print "file $path exists"}

This will report a file existing even though it doesn't. You might think that this is because we are using forwardslashes in windows BUT IF you then parse $path to replace the forwardslashes with backslashes (using a regular expression) it still doesn't work. BUT if you do this:
(leaving $path with forward slashes) it does work properly.

I suppose this is a bug?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-11 03:07 UTC]
I cannot reproduce this under Windows 2000 with PHP 4.0.6

Do you get the same error if you use a literal value instead of a variable.

var_dump (file_exists ("c:/some_random_file_name"));
var_dump (file_exists ("c:\\some_random_file_name"));
 [2001-07-11 14:50 UTC] ddruff at gemini1consulting dot com
The example in  my previous submission did not show the apparent bug. The example script did not match exactly what was going on in my actual script.

The problem seems to only occur when two file_exists statements are used in a row and the path argument used uses the same "slash style" (forward or backward) each time.

An example demonstrating the problem be dowloaded here:

(You will need to change the extension to php for it to work). 
 [2001-07-11 16:58 UTC]
The result of the call to file_exists() is cached. To clear the cache, call clearstatcache() before your second call to file_exists()

If this does not fix the problem, please reopen the bug. :)
 [2010-12-20 15:16 UTC]
-Package: Any +Package: *General Issues
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 09 20:01:27 2023 UTC