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

(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 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 

2 thoughts 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

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

  2. This will only affect your users if you are targeting the classic Mac OS environment for you app, and thus only if your users actually run your app -on their desktop- (and you can afford to spend time worrying about whether it’ll work on Classic Mac OS). If your php app is in the majority, and is a web-app, then you’re actually targeting A: servers (where use of Classic Mac OS is non-existent) and B: contributing developers (where I’m pretty certain most developers should be using OS X if they use anything at all).

    In my estimation, DIRECTORY_SEPARATOR is thus a minor, totally unnecessary thing for standard paths.