Bug #78939 [Com]: file_exists produces different results with TS and NTS builds
| From: | fisska at gmail dot com | Date: | Wed, 05 Jul 2023 10:16:55 +0000 |
| Subject: | Bug #78939 [Com]: file_exists produces different results with TS and NTS builds | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-244882@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
Comment by: fisska at gmail dot com
Reported by: michael dot vorisek at email dot cz
Summary: file_exists produces different results with TS and
NTS builds
Status: Open
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Windows
PHP Version: 7.3.12
Block user comment: N
Private report: N
New Comment:
1. Path format: In PHP, the file path format may vary depending on the operating system. On Windows,
both forward slashes (
/) and backslashes (\) are generally accepted as
directory separators. However, when using backslashes, you need to be careful because they are also
escape characters in PHP strings. So, when using backslashes, you need to escape them or use double
backslashes (\\) in the file path.
2. PHP build: The TS (Thread Safe) and NTS (Non-Thread Safe) builds of PHP can sometimes exhibit
slight differences in behavior. These differences are mainly related to the underlying threading
models used by PHP. It's possible that the way file functions handle paths can vary between the
TS and NTS builds.
3. File path validation: PHP does not strictly validate file paths by default. It relies on the
underlying operating system to handle file operations. If a file path is not recognized as a valid
path by the operating system, PHP's behavior may become unpredictable.
To address the issue you encountered, here are a few suggestions:
- Use the recommended file path format: It's generally recommended to use forward slashes
(/) or double backslashes (\\) when specifying file paths in PHP,
regardless of the operating system. This can help ensure consistency and compatibility across
different PHP builds.
- Normalize file paths: Before using file paths in PHP functions, it's a good practice to
normalize them using the realpath function. This function resolves any relative paths
and returns the absolute path, which can help avoid inconsistencies caused by different path formats
(https://github.com)(https://www.tellhappystar.org/).
- Be cautious with path assumptions: When working with file paths, it's important to consider
the assumptions made by different operating systems and PHP builds. Avoid relying on non-standard
path formats or behavior that may not be consistent across environments.
Previous Comments:
------------------------------------------------------------------------
[2021-10-14 15:36:58] cmb@php.net
Related To: Bug #60841
------------------------------------------------------------------------
[2019-12-10 18:14:40] cmb@php.net
This may very well be an issue of the PHP implementation.
------------------------------------------------------------------------
[2019-12-10 18:13:31] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #78939 - Windows relative path with drive letter
On GitHub: https://github.com/php/php-src/pull/5001
Patch: https://github.com/php/php-src/pull/5001.patch
------------------------------------------------------------------------
[2019-12-10 14:52:11] fgfgfgfdf at somewhere dot com
> PHP currently ignores this fact completely and resolves
> relative paths with drive letter like absolute ones
PHP resolves nothing, windows does
------------------------------------------------------------------------
[2019-12-10 14:28:21] michael dot vorisek at email dot cz
No! I am just reporting, that relative path with drive letter is not resolved correctly.
If this path format should be supported, it needs to be resolved like PHP resolve any other relative
relative paths. PHP currently ignores this fact completely and resolves relative paths with drive
letter like absolute ones.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78939
--
Edit this bug report at https://bugs.php.net/bug.php?id=78939&edit=1