Edit report at https://bugs.php.net/bug.php?id=79486&edit=1
ID: 79486
Comment by: m dot staab at complex-it dot de
Reported by: m dot staab at complex-it dot de
Summary: file_exists() returns true for a non-existing file
Status: Open
Type: Bug
Package: *General Issues
Operating System: windows10 x64
PHP Version: 7.4.5
Block user comment: N
Private report: N
New Comment:
you are right... opcache is disabled..
$ php -m
[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
filter
hash
iconv
json
libxml
mysqlnd
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
$ php -v
PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:19) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Previous Comments:
------------------------------------------------------------------------
[2020-04-17 12:21:48] sjon@php.net
if this is reproducible through the cli, you'd need opcache.enable_cli=1; did you enable that?
Did you try without enabling the opcache module?
------------------------------------------------------------------------
[2020-04-17 12:21:39] m dot staab at complex-it dot de
a few more tests
var_dump(is_readable($path . DIRECTORY_SEPARATOR . $file)); // true
var_dump(stat($path . DIRECTORY_SEPARATOR . $file));
array(26) {
[0]=>
int(2056)
[1]=>
int(19679399)
[2]=>
int(33204)
[3]=>
int(1)
[4]=>
int(1000)
[5]=>
int(1000)
[6]=>
int(0)
[7]=>
int(1)
[8]=>
int(1587125995)
[9]=>
int(1587125995)
[10]=>
int(1587125995)
[11]=>
int(-1)
[12]=>
int(-1)
["dev"]=>
int(2056)
["ino"]=>
int(19679399)
["mode"]=>
int(33204)
["nlink"]=>
int(1)
["uid"]=>
int(1000)
["gid"]=>
int(1000)
["rdev"]=>
int(0)
["size"]=>
int(1)
["atime"]=>
int(1587125995)
["mtime"]=>
int(1587125995)
["ctime"]=>
int(1587125995)
["blksize"]=>
int(-1)
["blocks"]=>
int(-1)
}
------------------------------------------------------------------------
[2020-04-17 12:18:45] m dot staab at complex-it dot de
when adding
```
file_get_contents($path . DIRECTORY_SEPARATOR . $file)
```
after the line which returns
```
file_exists($path . DIRECTORY_SEPARATOR . $file) == true
```
file_get_contents() will return false
also tested
```
var_dump(is_dir($path . DIRECTORY_SEPARATOR . $file)); // false
var_dump(is_file($path . DIRECTORY_SEPARATOR . $file)); // true
var_dump(is_link($path . DIRECTORY_SEPARATOR . $file)); // false
```
------------------------------------------------------------------------
[2020-04-17 12:14:12] m dot staab at complex-it dot de
Description:
------------
I am running into a mysterious problem, where php's file_exists() returns TRUE for a path,
where no file exists.
I tried opening the filepath via notepad++ or the windows explorer, and every tool is telling me
that the path points to a non-existant file... except php..
putting the offending path into a plain 3 lines php file it reports false though.
since its really hard to reproduce (even when copying the paths 1:1) it might be a deeper php issue,
e.g. opcache statcache or similar.
I tried invoking clearstatcache() before the file_exists() but this does not change the output
Test script:
---------------
error not reproducible with
```
<?php
var_dump(file_exists('C:\Users\mstaab\Documents\GitHub\kunzmann\app\shop\models\clxBaureihe.php'));
```
but at runtime when my sources look like things look different
foreach (array(
self::$model_paths,
self::$lib_paths,
self::$helper_paths,
self::$controller_paths,
self::$plugin_paths
) as $paths) {
foreach ($paths as $path => $dummyVal) {
if (file_exists($path . DIRECTORY_SEPARATOR . $file)) {
if ($class_name == 'clxBaureihe') {
var_dump($class_name); // "clxBaureihe"
var_dump($path); //
"C:\Users\mstaab\Documents\GitHub\kunzmann/app/shop/models"
var_dump($file); // "clxBaureihe.php"
var_dump($path . DIRECTORY_SEPARATOR . $file); //
"C:\Users\mstaab\Documents\GitHub\kunzmann/app/shop/models\clxBaureihe.php"
var_dump(file_exists($path . DIRECTORY_SEPARATOR . $file)); // bool(true)
}
Expected result:
----------------
file_exists() should return false on non-existing files
Actual result:
--------------
it returns true
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79486&edit=1