as a long time windows user and php developer, i can only say: do not use
DIRECTORY_SEPARATOR! it has no real benefit but really can break things.
/. it is the better choice nearly every time.
if you use
DIRECTORY_SEPARATOR, which resolves to
\ on windows, things tend to break. For example:
\ gets converted to
%5C in urls.
DIRECTORY_SEPARATOR is used, it easily happens that the (relative) path, which will contain a backslash on windows, is passed to something which should be a url. assuming that most of the php developers are using linux or mac (i personally don't know many people who develop php on windows), they don't notice that in a windows environment a backslash is passed to the url and gets escaped as
%5C which leads to urls like in the example above.
windows and php on windows are capable of opening files with the path
DIRECTORY_SEPARATOR is of no real use except for easily detecting windows or for example if you export a path for a file list where a windows user would be confused to see
/ instead of
λ cat ./foo/bar\example/test.txt mycontent
cat exists on windows)
also opens the file
<?php $content = file_get_contents('foo/bar\example/test.txt'); var_dump($content);
λ php foo.php C:\test\foo.php:5: string(9) "mycontent"
even that works:
<?php $content = file_get_contents('c:/foo/bar\example/test.txt'); var_dump($content);
- cat for windows is shipped with git for windows https://git-scm.com/download/win
λcomes from the shell i use. http://cmder.net/
- meme linked from https://imgflip.com/
- cover image by wezlo https://www.pexels.com/photo/caution-dead-end-post-safety-237189/ https://pixabay.com/en/sign-street-dead-end-1749093/