Bug #78939 [Fbk]: file_exists produces different results with TS and NTS builds
| From: | requinix@php.net | Date: | Tue, 10 Dec 2019 13:22:57 +0000 |
| Subject: | Bug #78939 [Fbk]: file_exists produces different results with TS and NTS builds | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224196@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78939&edit=1
ID: 78939
Updated by: requinix@php.net
Reported by: michael dot vorisek at email dot cz
Summary: file_exists produces different results with TS and
NTS builds
Status: Feedback
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Windows
PHP Version: 7.3.12
Block user comment: N
Private report: N
New Comment:
That might have been a bit blunt. My point is, you had some sort of problem that you tracked down
(congratulations) to some sort of incorrect file path configuration... code... something. And now
you have learned that "C:x.txt" and "C:/x.txt" can potentially mean two
different things because the former is a relative path and the latter is absolute.
Normally this sort of situation becomes resolved at this point because it's considered an issue
of user education, and once the teaching is done and the code is fixed, everything starts working
again. But you're apparently looking for something more and I, personally, am not seeing what
should happen next. It's not like the behavior is wrong - maybe it's a bit unexpected, but
that isn't PHP's fault. The only thing I can think of is documentation, but there are
*tons* of little Windows nuances out there and I don't think it's reasonable to expect PHP
to try to cover them. Prohibit the unusual behavior? That seems like it would punish more people for
using the feature than help people who were accidentally using it (and somehow not noticing a
problem?).
Previous Comments:
------------------------------------------------------------------------
[2019-12-10 13:06:22] requinix@php.net
There's no support to remove. It's Windows doing this, not PHP. What you want is to *add a
restriction* that PHP on Windows will not allow an uncommon but very much valid pattern for a file
path.
And what's the rationale for this, again? Because "a lot of people are not aware of
it"? Got anything better?
------------------------------------------------------------------------
[2019-12-10 12:58:27] michael dot vorisek at email dot cz
Yes, if relative path with drive letter should be supported, PHP must process it the same way it
resolves standard relative paths like '../x.txt' and support php.ini directived like
include_path.
Or simply remove the support for it and display PHP warning, as the format is very confusing, not
supported even by explorer.exe (but other relative formats are) and a lot of people are not aware of
it.
------------------------------------------------------------------------
[2019-12-10 11:38:25] requinix@php.net
C:x.txt is a valid path: it references x.txt in the process's current working directory on the
C drive.
https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats
I imagine the NTS build is inheriting the C: working directory from whatever process you used to
spawn it. This would be one of those "different in more ways than just threading" aspects
I mentioned in the other report.
Ultimately it is a relative path, and relative paths are subject to the environment.
------------------------------------------------------------------------
[2019-12-10 11:28:41] michael dot vorisek at email dot cz
Description:
------------
After spending a lot of time why PHP app does work on one PC and not on another, comparing gigabytes
of logs, I find very weird behaviour of core PHP file function.
var_dump(file_exists('C:x.txt'));
if the file "C:/x.txt" exists, PHP produces different results with TS and NTS builds on
Windows if the path is without slash after "C:", i.e.
- output for "C:/x.txt" is corrent and consitent across TS and NTS builds
- output for "C:x.txt" differs across TS and NTS builds
The path format without slash after "C:" is not supported in explorer.exe, so for me it
seems that paths like "C:something" should be considered invalid and the TS build should
be fixed to always return false.
Note: other file functions are probably affected too.
Test script:
---------------
// 1. manually create any/empty file and save it under "C:/x.txt"
// 2. run this code with PHP TS and PHP NTS
var_dump(ZEND_THREAD_SAFE);
var_dump(file_exists('C:/x.txt'));
var_dump(file_exists('C:x.txt'));
// 3. notice the different output of the 3rd line
Expected result:
----------------
// expected output from PHP TS and NTS
bool(true) OR bool(false) // dump of ZEND_THREAD_SAFE constant
bool(true)
bool(true) OR bool(false) // TBD, path without slash after "C:" - see desc., but output
need to be consistent across TS and NTS PHP builds
Actual result:
--------------
// output from PHP TS
bool(true)
bool(true)
bool(true)
// output from PHP NTS
bool(false)
bool(true)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78939&edit=1