Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to understand examples in PSR-0, but to no avail. I know that is directory separator (at least in my windows OS), and in my humble opinion, it can't be equivalent to /. I googled the difference between them and found no result.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

When running under Linux or MacOS, PHP only allows / as a directory separator.

When running under Windows, PHP accepts either / or as a directory separator; it treats them exactly the same.

In virtually all cases, it is better to always use /, because that will allow your code to run on any platform. If you use for directory separators, then your code will only work on Windows.

The difference on Windows is to allow compatibility with other software that might provide paths with separators, but unless you specifically need to do that, it's best to stick with /.

Also, there is another use of in PHP which might be confusing you (particularly as you mentioned PSR0). The is also the separator for PHP namespaces.

Namespaces are not the same as directory separators, but they can end up looking like them, because common practice is to organise a project such that the namespaces match the directory structure. This is done to make your code modules easy to find and easy to write an autoloader for them, and it is thus the recommended way of structuring a project as per PSR0, but it is not compulsory in the PHP language; namespaces are not the same as directory paths.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...