phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Reproduce autoloader bug

Open staabm opened this issue 7 months ago • 0 comments

this test demonstrates how PHPStan analyzes code differently than it would happen at runtime.


runtime: run php real-world.php you see the program runs, without the custom autoloader of e2e/bug-12972b/autoloader.php beeing invoked. all involved classes are autoloaded by the composer class loader. the custom class loader is not invoked for \other12972\MyClass::class.


static analysis time: run ../../bin/phpstan analyze

you see PHPStan invokes the custom class loader for class \other12972\MyClass::class, which does not happen at regular runtime. the composer class loader is not invoked for \other12972\MyClass::class (like it is at runtime).

because of the difference in autoloading functions order in runtime vs. analysis time we see errors which cannot happen at runtime - see https://github.com/phpstan/phpstan/issues/12972

staabm avatar May 21 '25 08:05 staabm