php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71103 file_exists and is_readable fail silently
Submitted: 2015-12-12 16:21 UTC Modified: 2016-08-08 10:10 UTC
Votes:3
Avg. Score:3.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: flip101 at gmail dot com Assigned: ab (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.6.16 OS: Windows
Private report: No CVE-ID: None
 [2015-12-12 16:21 UTC] flip101 at gmail dot com
Description:
------------
file_exists and is_readable return false on windows when file exist but full path is longer than 258 characters. This seems related to MAX_PATH https://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath

The best expected result would be just return true (see box expected result), then these functions should use the unicode version of the windows API.

In case it's not desirable to use the unicode version of the windows API. Then the expected result would be generate PHP Warning. Now it just return a wrong result without notification.

Test script:
---------------
<?php
$foo = 'D:\\dev\\http\\tproj\\app\\cache\\dev_old\\annotations\\72\\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b.doctrinecache.data';
$bar = 'D:\\dev\\http\\tproj\\app\\cache\\dev_old\\annotations\\72\\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b315d.doctrinecache.data';
$foo_obj = new \SplFileInfo($foo);
$bar_obj = new \SplFileInfo($bar);
var_dump($foo, file_exists($foo), file_exists($foo_obj));
var_dump($bar, file_exists($bar), file_exists($bar_obj));

Expected result:
----------------
D:\dev\http\tproj>php del.php
string(258) "D:\dev\http\tproj\app\cache\dev_old\annotations\72\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e43
6f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b.doctrinecache.data"
bool(true)
bool(true)
string(262) "D:\dev\http\tproj\app\cache\dev_old\annotations\72\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e43
6f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b315d.doctrinecache.data"
bool(true)
bool(true)

D:\dev\http\tproj>dir D:\dev\http\tproj\app\cache\dev_old\annotations\72\
 Volume in drive D is Data
 Volume Serial Number is 2E83-BAB4

 Directory of D:\dev\http\tproj\app\cache\dev_old\annotations\72

01-12-2015  15:09    <DIR>          .
01-12-2015  15:09    <DIR>          ..
01-12-2015  15:04                 9 5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c65722367657441
6e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b.doctrinecache.data
01-12-2015  15:01                 9 5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c65722367657441
6e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b315d.doctrinecache.data
               2 File(s)             18 bytes
               2 Dir(s)   7.241.150.464 bytes free

Actual result:
--------------
D:\dev\http\tproj>php del.php
string(258) "D:\dev\http\tproj\app\cache\dev_old\annotations\72\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e43
6f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b.doctrinecache.data"
bool(true)
bool(true)
string(262) "D:\dev\http\tproj\app\cache\dev_old\annotations\72\5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e43
6f6e74726f6c6c657223676574416e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b315d.doctrinecache.data"
bool(false)
bool(false)

D:\dev\http\tproj>dir D:\dev\http\tproj\app\cache\dev_old\annotations\72\
 Volume in drive D is Data
 Volume Serial Number is 2E83-BAB4

 Directory of D:\dev\http\tproj\app\cache\dev_old\annotations\72

01-12-2015  15:09    <DIR>          .
01-12-2015  15:09    <DIR>          ..
01-12-2015  15:04                 9 5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c65722367657441
6e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b.doctrinecache.data
01-12-2015  15:01                 9 5b53796d666f6e795c42756e646c655c5477696742756e646c655c436f6e74726f6c6c65725c457863657074696f6e436f6e74726f6c6c65722367657441
6e64436c65616e4f7574707574427566666572696e67405b416e6e6f745d5d5b315d.doctrinecache.data
               2 File(s)             18 bytes
               2 Dir(s)   7.241.150.464 bytes free

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-13 02:24 UTC] laruence@php.net
-Assigned To: +Assigned To: ab
 [2016-08-08 10:10 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2016-08-08 10:10 UTC] ab@php.net
Fixed in PHP 7.1, please read UPGRADING.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 22:01:30 2024 UTC