khernik
khernik

Reputation: 259

PHP namespaces and flexible folder structure

I let my users to change the name of the system folder. I also use namespaces in its classes. The name of the system folder is being kept in the global constant.

The autoloading searches for the file based on its namespace.

So, let's say I have a folder called system and a class:

\Project_Name\System\Something;

And a user changes this folder into "something_else". The namespace will not match the folder structure and the class won't be loaded.

Is there any way to prevent this? Maybe using constant in the namespace's name?

And one other question:

Will the autoloaded class always have "\" at the beginning of its name? Even if the class belongs to some relative namespace?

Upvotes: 0

Views: 204

Answers (1)

Naftali
Naftali

Reputation: 146310

Do not let them

If your library is dependent on a PSR-0 (or any other) namespacing schema, let your users know that they cannot change the folder names or the library will not work.

If they change the folder names -- that is their problem to fix, not yours to solve.

Upvotes: 3

Related Questions