In attempting to write cross-platform, portable PHP engine, I was using PHP's DIRECTORY_SEPARATOR constant to write path strings(eg ".." . DIRECTORY_SEPARATOR . "foo.php", because the proper way to write it in Windows would be "\" while in Unix it would be "/".
Well, an engineer from php.net pointed out to me that, and a few other programmers confirmed that using that constant is completely unnecessary. As long as you use the forward slash (/), you'll be fine. Window's doesn't mind it, and it's the best for *nix operating systems.
(Note that DIRECTORY_SEPARATOR is still useful for things like exploding a path that the system gave you.)
Hope this is useful to people.
The Following 4 Users Say Thank You to TerrorRonin For This Useful Post:
Very useful. Thanks Robin! It leaves me astonished how PHP cannot stick to naming conventions even with their constants. I have to admit, I've not heard of the DIRECTORY_SEPARATOR before -- my bad! However, if they'd prepended it with PHP_, I may have stood a chance at finding it. That way it would have appeared in the auto-complete list on the day I found PHP_EOL.
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
But can you use both of them in one request? Because I always use getcwd() which returns something like this in Windows: C:\Bla\Bla and if I append my path without using DIRECTORY_SEPARATOR I will get something like this: C:\Bla\Bla/linux/style/path but will that work?