Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When to use DIRECTORY_SEPARATOR? #9

Open
donquixote opened this issue Jul 11, 2013 · 3 comments
Open

When to use DIRECTORY_SEPARATOR? #9

donquixote opened this issue Jul 11, 2013 · 3 comments

Comments

@donquixote
Copy link
Owner

Other class loaders (Symfony, Composer) work a lot with the DIRECTORY_SEPARATOR constant.

As I can read somewhere, this is meant for Windows, but simply using slash would work just fine.
Although, here it is pointed out this is also for "Mac OS Classic":
http://stackoverflow.com/questions/625332/is-using-the-directory-separator-constant-neccessary

On Windows, you only need it if you deal with paths provided by the system, or if you want to mix system-provided and user-provided paths, and want to avoid a mixture of slash and backslash.

So far so good.
The little "problem" is, that ClassLoader_Pluggable::addNamespacePlugin() actually takes a "$logicalBasePath" as its first argument, and this must have the correct separator. The "RegistrationHub" does the conversion from namespace to logical path. But if you register your stuff directly on the class loader, then you need to take care to replace every slash with directory separator. Baaad.

@donquixote
Copy link
Owner Author

Here is a funny solution:

e0f60ac

@donquixote
Copy link
Owner Author

And here is a fix that fixes the only place where we did register a logical path with incorrect directory separator.

4939e4c

@paul-vg
Copy link
Contributor

paul-vg commented Jul 25, 2013

Yes, the constant is only relevant when dealing with paths obtained from the system (e.g. you're parsing getenv("PATH")). No, it's not useful for avoiding a mixture of delimiters. You may parse a path with either delimiter (e.g. reading a path from a config file) and output the path using only / (i.e. normalised to the generic delimiter). Accessing a file using / delimiters always works, Windows actually supports mixed delimiters within a single path specification.

PHP isn't supported on "classic" MacOS, the INSTALL used to explicitly state this fact. I reckon it's going to be difficult setting up a recent version of PHP on ancient OS X versions as well.

The second commit is fine in itself, but you can safely avoid the extra code and strcat operation by using / whenever a path is constructed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants