Bug #79486 [Com]: file_exists() returns true for a non-existant file
| From: | m dot staab at complex-it dot de | Date: | Fri, 17 Apr 2020 12:18:45 +0000 |
| Subject: | Bug #79486 [Com]: file_exists() returns true for a non-existant file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226636@lists.php.net to get a copy of this message | ||
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-existant 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:
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
```
Previous Comments:
------------------------------------------------------------------------
[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