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

Most upvoted comments

@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-autoloader on install/update and then call dump-autoload explicitly after with the right flags.