{"record":{"id":"8dcd5c3a025967b8","repo":"composer/composer","slug":"strict-psr-autoloader-mode-only-works-with-optim","errorCode":null,"errorMessage":"--strict-psr-autoloader mode only works with optimized autoloader, use --optimize-autoloader or --classmap-authoritative if you want a strict return value.","messagePattern":"--strict-psr-autoloader mode only works with optimized autoloader, use --optimize-autoloader or --classmap-authoritative if you want a strict return value\\.","errorType":"exception","errorClass":"\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/InstallCommand.php","lineNumber":125,"sourceCode":"        if (!$composer->getLocker()->isLocked() && !HttpDownloader::isCurlEnabled()) {\n            $io->writeError('<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>');\n        }\n\n        $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);\n        $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);\n\n        $install = Installer::create($io, $composer);\n\n        $config = $composer->getConfig();\n        [$preferSource, $preferDist] = $this->getPreferredInstallOptions($config, $input);\n\n        $optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');\n        $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');\n        $apcuPrefix = $input->getOption('apcu-autoloader-prefix');\n        $apcu = $apcuPrefix !== null || $input->getOption('apcu-autoloader') || $config->get('apcu-autoloader');\n\n        if ($input->getOption('strict-psr-autoloader') && !$optimize && !$authoritative) {\n            throw new \\InvalidArgumentException('--strict-psr-autoloader mode only works with optimized autoloader, use --optimize-autoloader or --classmap-authoritative if you want a strict return value.');\n        }\n\n        $composer->getInstallationManager()->setOutputProgress(!$input->getOption('no-progress'));\n\n        $install\n            ->setDryRun($input->getOption('dry-run'))\n            ->setDownloadOnly($input->getOption('download-only'))\n            ->setVerbose($input->getOption('verbose'))\n            ->setPreferSource($preferSource)\n            ->setPreferDist($preferDist)\n            ->setDevMode(!$input->getOption('no-dev'))\n            ->setDumpAutoloader(!$input->getOption('no-autoloader'))\n            ->setOptimizeAutoloader($optimize)\n            ->setClassMapAuthoritative($authoritative)\n            ->setStrictPsrAutoloader($input->getOption('strict-psr-autoloader'))\n            ->setApcuAutoloader($apcu, $apcuPrefix)\n            ->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input))\n            ->setPolicyConfig($this->createPolicyConfig($composer->getConfig(), $input))","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/InstallCommand.php#L107-L143","documentation":"In InstallCommand::execute, `--strict-psr-autoloader` (which makes the command exit with code 6 on PSR-4/PSR-0 mapping errors) is only meaningful when the autoloader is dumped in optimized mode. If neither --optimize-autoloader/-o nor --classmap-authoritative/-a is in effect (and config does not enable them), Composer throws InvalidArgumentException because strict checks would run against a non-optimized autoloader and silently never fire.","triggerScenarios":"Running `composer install --strict-psr-autoloader` (or update/dump-autoload with the flag) without also enabling optimization. The check at InstallCommand.php:124 fails when both $optimize and $authoritative are false.","commonSituations":"CI pipelines that add `--strict-psr-autoloader` to catch PSR violations but forget the required optimizer flag; copying the flag from docs without -o.","solutions":["Add --optimize-autoloader (or -o): `composer install --strict-psr-autoloader --optimize-autoloader`.","Or use --classmap-authoritative (or -a), which implicitly enables optimization.","Or set optimize-autoloader / classmap-authoritative in config so the flag has the prerequisite."],"exampleFix":"// before\ncomposer install --strict-psr-autoloader\n// after\ncomposer install --strict-psr-autoloader --optimize-autoloader","handlingStrategy":"validation","validationCode":"$opts = ['strict-psr-autoloader','optimize-autoloader','classmap-authoritative'];\nif (in_array('strict-psr-autoloader', $argv, true)\n    && !in_array('optimize-autoloader', $argv, true)\n    && !in_array('classmap-authoritative', $argv, true)\n    && !in_array(['-o','-a'], array_slice($argv, -2), true)) {\n    throw new \\InvalidArgumentException('strict-psr-autoloader needs optimization');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair --strict-psr-autoloader with -o/-a in CI configs.","Centralize the install flags in a Makefile/script so the combo stays correct."],"tags":["install-command","validation","autoloader","cli-options","psr-4"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}