Prepend, multiple paths, and underscore combined with namespaces. #5

merged 4 commits into from Jul 10, 2012


None yet
2 participants

boenrobot commented Feb 8, 2012

I've added some prepend options to allow users to specify custom paths with precendence over the path PEAR2_Autoload is in. This is particularly useful in test suites, where one might want to ensure the code under test is loaded while another "stable" version is still on the system.

Also, multiple paths can be specified at once, separated by PATH_SEPARATOR.

Another change that's part of the same commit, and I realize I may be opening a can of worms with it... if the class is in a namespace, an underscore is not replaced. This allows classes and filenames to have an underscore as part of their actual name, while namespaces will be used for logical separation. A class that's not in a namespace will of course still have its name separated by an underscore.

So, before:

new MyNamespace\fancy_structure; //Resolves to "MyNamespace/fancy/structure.php"
new MyNamespace_fancy_structure; //Resolves to "MyNamespace/fancy/structure.php"

and now

new MyNamespace\fancy_structure; //Resolves to "MyNamespace/fancy_structure.php"
new MyNamespace_fancy_structure; //Resolves to "MyNamespace/fancy/structure.php"

Should I maybe add it as an option (with the prepend options being specified as a bitmask, this should be easy)? If so, what should be the default? The current or new one?


boenrobot commented Mar 14, 2012

Anything on this?

BTW, now that PHP 5.4 is out, I think supporting traits would be nice.


saltybeagle commented Jul 10, 2012

Changing the way that underscores are treated within the CLASS NAME would make the autoloader incompatible (less compatible than we are already) with PSR-0:

  • Each "" character in the CLASS NAME is converted to a
    " character has no special meaning in the

The trait additions are good, as well as the prepend options — no objections to that.

@boenrobot boenrobot Made the load PSR-0 compliant;
Changed the require statements to includes to remove the remaining PHPCS issues;
Changed the file_exists() checks into is_file() checks, since folders can't be included.

boenrobot commented Jul 10, 2012

Good point. At the time, I didn't saw PSR-0 addressing underscores in namespaced classes in any way. I've now changed the load to be PSR-0 compliant. It's in fact an altered version of the doc :-P .

I've also made some other minor fixes for PHPCS' sake.


saltybeagle commented Jul 10, 2012

Excellent. I think we need to improve the test-coverage, but this is looking really good.

saltybeagle merged commit dbe02ce into pear2:master Jul 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment