Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a PATH_SEPARATOR constant?

Tags:

php

Isn't this / ?

Why is there a constant for it? It's not like it can change, right?

like image 951
Alex Avatar asked Mar 19 '12 11:03

Alex


People also ask

What is Directory_separator?

DIRECTORY_SEPARATOR is constant with that OS directory separator. Use it every time in paths. In you code snippet we clearly see bad practice code. If framework/cms are widely used it doesn't mean that it's using best practice code. Follow this answer to receive notifications.

What is the directory separator in Linux?

If you prefer to hard-code the directory separator character, you should use the forward slash ( / ) character. It is the only recognized directory separator character on Unix systems, as the output from the example shows, and is the AltDirectorySeparatorChar on Windows.


2 Answers

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.

like image 54
AlterPHP Avatar answered Sep 23 '22 01:09

AlterPHP


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 /

like image 26
Ben Rowe Avatar answered Sep 26 '22 01:09

Ben Rowe