|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-07-12 08:20 UTC] rasmus at mindplay dot dk
Description:
------------
The UNIX_PATHS flags, according to documentation, "Makes paths use Unix-style forward slash irrespective of system default".
This is important e.g. for the purposes of comparing paths, but it doesn't seem to have any effect on Windows. The paths have backslashes regardless of setting this flag.
I also tried setting the CURRENT_AS_PATHNAME flag, since I suspected this was due to the fact that iterators etc. likely *can't* impose this change on SplFileInfo instances in the first place? Even if they could, that would make the behavior of SplFileInfo::getPathname() somewhat unpredictable.
I'm currently forced to do something like $path = strtr('\\', '/', $path) in every program that compares paths, to make sure it works on Windows, which is really messy.
(I often find myself wondering why backslashes are used in paths on Windows at all? Since forward slashes work just fine. One usually cares more about paths being comparable, e.g. actually working and behaving predictably and consistently, than what it looks like when printed on screen...)
Test script:
---------------
<?php
$files = new RecursiveDirectoryIterator(
__DIR__, // (or somewhere specific)
RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS
);
foreach ($files as $file) {
var_dump($file->getPathname()); // paths with backslashes :-(
}
Expected result:
----------------
UNIX-style forward slashes, per the description of the flag.
Actual result:
--------------
Mixed Windows/UNIX-style backslashes and forward slashes.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
I can confirm this behavior. I'm not sure, whether this qualifies as implementation or a documentation bug, though. Of course, the mixed directory separators are usually not desired, but still the implementation would make some sense, as only the given $path will contain Windows directory separators, but not the rest, cf. <?php $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( __DIR__, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS ) ); foreach ($files as $file) { var_dump($file->getPathname()); // paths with mixed dir separators } > I often find myself wondering why backslashes are used in paths > on Windows at all? Consider exec(), for instance.