Fix composer autoload from classmap to files#3
Conversation
Use "files" autoloading instead of "classmap". This will make composer auto-require the file, and allow it to be actually used properly.
|
I'm happy to merge the fix if I can establish why, but can you please supply more details about what doesn't work and why I create the following {
"require": {
"docopt/docopt": "0.6.*"
}
}Then the following PHP: <?php
require __DIR__.'/vendor/autoload.php';
var_dump(class_exists('Docopt\Handler', false));
$h = new Docopt\Handler();
var_dump(class_exists('Docopt\Handler', false));The output is this: |
|
Classmap only works for classes. Since the file also contains functions, files will make sure those functions can be used as well, without requiring the class to be instantiated first. In particular the |
|
Ahh, cheers, I understand now. Thanks for reporting. The I think the interim solution is to recommend that you use the I'm not overly fond of the verbosity of |
|
It's a known limitation of PHP autoloading that you cannot autoload functions. Which is unfortunate. I still think a function is more correct than a static method, and worth the small penalty of loading the file. But the static method solution works as well, so if you want to go with that, that's fine with me. |
Use "files" autoloading instead of "classmap". This will make
composer auto-require the file, and allow it to be actually used
properly.