Is the PHP Directory_Separator constant really needed?

A lot of coders use the PHP constant DIRECTORY_SEPARATOR to define paths that will work on Windows as well as other platforms.

However, I read here that is not needed for defining paths because Windows allows for the slashes to be both ways, which was left by Christian here on php.net.

(And to be honest, I rarely use the constant because I know this is the case for Windows)

But… what is the uber best practice? According to Jan Jungnickel one SHOULD use it because e.g. Mac OS Classic uses ":" (and see that last wikipedia page for more examples of other operating systems using different variants).

(ofcourse when exploding and parsing you would need it but I'm referring here to defining paths)

So… I come to the conclusion (with http://en.wikipedia.org/wiki/Path_%28computing%29 as a good example) that it is probably the most elegant and most cross platform to use this constant for defining paths.

But I would gladly hear your comment on that one.

Tagged with 

One thought on “Is the PHP Directory_Separator constant really needed?

  1. I think the Directory_Separator is used for file-system paths, not for URI’s. Furthermore, the RFC specifies the use of the slash-character http://tools.ietf.org/html/rfc3986#section-3.3

    It is up to the webserver (i.e. Apache) that processes the slash-separator to convert the slashes to the filesystem separator.

Comments