composer: Support strict (no ambiguous classes) mode for generating optimised autoloader
I’d love a composer install --optimize-autoloader --prevent-ambiguous (or similar named) option to make the install fail (rather than just print a warning) if it finds ambiguous class definitions.
The resolution of ambiguous class names is platform-dependent (the order composer finds the files varies between filesystems) which can lead to composer autoloading a totally different implementation of a class between development / build / production instances. Similarly classes contained in files that don’t match the PSR-0/4 definition won’t cause issues locally but may be found and used when the classmap is generated. For example this can happen if working / backup files are accidentally committed, or if a (badly-configured) dependency with a loose psr-0 definition comes with test / example files.
It can be very hard to debug and trace the problems this causes. They can arise at any time (even if the composer dependencies don’t actually change), so a developer might not always notice them. Often the “Ambiguous class resolution” warnings will only arise within a remote build / deployment process and not be noticed - particularly if the composer command output doesn’t appear in deployment logs.
So I’d like to be able to opt-in to have composer fail with an error if ambiguous classes are found, to force the end-user to fix that rather than hope the resolution is always going to be correct now and in future.
I’m happy to work on a PR if you agree this is a good idea?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (14 by maintainers)
Commits related to this issue
- Add --strict-ambiguous to dump-autoload command Fixes #6221 — committed to Seldaek/composer by Seldaek 2 years ago
- Add --strict-ambiguous to dump-autoload command (#12119) Fixes #6221 — committed to Boo-hub33/composer by Seldaek 2 years ago
- Add hint how ambiguous class issues can be resolved, refs #6221 — committed to Seldaek/composer by Seldaek 2 years ago
- Add hint how ambiguous class issues can be resolved, refs #6221 — committed to Seldaek/composer by Seldaek 2 years ago
- Add hint how ambiguous class issues can be resolved, refs #6221 (#12179) — committed to composer/composer by Seldaek 2 years ago
@Kenneth-Sills not really, sorry but the amount of flags on install/update is already very large and adding super specific ones like risks drowning the important ones… The better way to integrate this IMO is to use
--no-autoloaderon install/update and then call dump-autoload explicitly after with the right flags.