Good day. Faced the problem of implementing the dependency manager composer in a project where namespaces were not used in principle. There was a problem describing the global namespace, i.e. in composer.json I write:

"autoload": { "psr-4": { "mynamespace\\": "src/classes", "\\": "src/global" } } 

That is, I try to indicate that all classes in which the namespace is not spelled out, and which are accessed via \ (\ User), are in the src / global folder. But in this case, such global classes are still not found and have to use require_once. In the case of mynamespace, everything works out normally. Thanks for attention!

  • as far as I understand, you need to specify an empty string, but not "\\" - etki

1 answer 1

I found a solution in using the classmap parameter ( https://getcomposer.org/doc/04-schema.md#classmap -):

 "autoload": { "classmap": ["src/global"] } 

Also, to exclude automatic class loading from specified directories, you can use the exclude-from-classmap parameter. Maybe someone will come in handy.