From 7606e71cc4836b23070d22578a4b727c8d2a8b0f Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Thu, 11 Jun 2026 10:53:00 +0200 Subject: [PATCH] fix: invalidate cache when a different --autoload-file is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A different extra autoload changes what PHPStan can resolve, so cached results must not survive it. Repro: run without -a (helper functions unresolvable, files cached clean), then run with -a — the fresh inference suggestions stay hidden until --clear-cache. The configuration hash already includes the parameter bag, so registering the resolved autoload file path there at boot is enough. Co-Authored-By: Claude Opus 4.8 --- bin/rector.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/rector.php b/bin/rector.php index 5860ed1b7d0..48a0cc6e8bb 100755 --- a/bin/rector.php +++ b/bin/rector.php @@ -6,6 +6,7 @@ use Rector\Bootstrap\RectorConfigsResolver; use Rector\ChangesReporting\Output\JsonOutputFormatter; use Rector\Configuration\Option; +use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\Console\Style\SymfonyStyleFactory; use Rector\DependencyInjection\LazyContainerFactory; use Rector\DependencyInjection\RectorContainerFactory; @@ -127,6 +128,14 @@ public function loadIfExistsAndNotLoadedYet(string $filePath): void $autoloadIncluder->autoloadRectorInstalledAsGlobalDependency(); $autoloadIncluder->autoloadFromCommandLine(); +// a different extra autoload changes what PHPStan can resolve, so cached results +// must not survive it: register it before the configuration hash is computed. +// ArgvInput handles both "--autoload-file path" and "--autoload-file=path" +$autoloadFileOption = (new ArgvInput())->getParameterOption(['--autoload-file', '-a'], null); +if (is_string($autoloadFileOption) && $autoloadFileOption !== '') { + SimpleParameterProvider::setParameter(Option::AUTOLOAD_FILE, realpath($autoloadFileOption) ?: $autoloadFileOption); +} + $rectorConfigsResolver = new RectorConfigsResolver(); try {