0
votes

Composer dump-autoload doesn't work successfully unless the optimize flag (-o) is used.

I have a composer.json with the following:

  "autoload": {
"psr-4": {
  "ClassSrcFolder_TopLevelNamespace\\": "app/ClassSrcFolder/"
}

}

Running "composer dump-autoload" w/o the -o flag I get a "class not found" error for a sub-folder to the "app/ClassSrcFolder/"

Is there a reason for this behavior?

1

1 Answers

1
votes

When you add a new class composer can immediately be discovered/used without having to rebuild the autoloader configuration as long as a PSR-4 mapping rule has been added to the instance or defined in the configuration. This means that if you are trying to access a namespace with no mapping, it will throw the error unless you run the optimizer that creates the mapping for all of your php dependencies. Check the autoload_classmap file inside composer folder.

"config": {
        "optimize-autoloader": true
    }

Should keep you from having to use the -o flag.