Isn't this /
?
Why is there a constant for it? It's not like it can change, right?
PATH_SEPARATOR
is the character used to separate many paths in a unique string (like include_path
in php.ini).
Its value is ':'
on a UNIX system and ';'
on a Windows system.
What you're talking about ('/'
on UNIX and '\'
on Windows) is the DIRECTORY_SEPARATOR
constant.
As your original question states: "Why is there a PATH_SEPARATOR constant?", windows uses a semi-colon ;
, while other systems use a colon :
However I think you've mistaken PATH_SEPARATOR with DIRECTORY_SEPARATOR
PATH_SEPARATOR delimits multiple paths in the same string. For example when used in windows environment variables.
c:\path\to\a;
c:\path\to\b
DIRECTORY_SEPARATOR separates the directories within the path: In Windows
\
In other systems
/
As mentioned by others, windows also accepts /
cd /valid/path/
in windows. I think you'll find that this works
system("dir /mydirectory")
- it will complain, because it thinks that's a parameter to the dir
command. So although PHP supports /
, you can easily end up with weird problems because you assumed it's going to work everywhere. I just wanted to point out this.
Feb 11, 2013 at 15:47
It can. It is \
in Windows and /
in Linux (and prettymuch everywhere else), although modern versions of Windows do accept /
as a separator.
Ooops this is about the DIRECTORY_SEPARATOR
constant.
PATH_SEPARATOR
is indeed the constant to separate various paths as seen in PéCés answer.