Skip to content

autoloading issues since 1.7.x #7308

@staabm

Description

@staabm

Bug report

atm we are kind of stuck on phpstan 1.6.8 because with 1.7.x we experience autoloading issues.

I was not yet able to build a small reproducing example, but it seems we see some kind of race conditions on which classes are known to phpstan and when. running in single process --debug mode most of the time works, but running regular multi process phpstan analysis often times crashes like

Uncaught Error: Class "clxElement" not found in C:\dvl\Workspace\motiontm\lib\plugins\clxMobileNet\lib\clxShop.php:3
#0 C:\dvl\Workspace\motiontm\vendor\plugins\rocket\lib\Rocket.php(387): require_once()
#1 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(270): Rocket::autoload()
#2 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php(59): PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator::PHPStan\Reflection\BetterReflection\SourceLocator\{closure}()
#3 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(282): PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::withStreamWrapperOverride()
#4 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(114): PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateClassByName()
#5 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28): PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateIdentifier()
#6 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33): PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#7 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32): PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#8 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionClass.php(871): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass()
#9 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionClass.php(367): PHPStan\BetterReflection\Reflection\ReflectionClass->getParentClass()
#10 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionClass.php(410): PHPStan\BetterReflection\Reflection\ReflectionClass->getParentMethods()
#11 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionClass.php(459): PHPStan\BetterReflection\Reflection\ReflectionClass->getMethodsIndexedByName()
#12 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionClass.php(674): PHPStan\BetterReflection\Reflection\ReflectionClass->getMethods()
#13 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/Adapter/ReflectionClass.php(123): PHPStan\BetterReflection\Reflection\ReflectionClass->getConstructor()
#14 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(440): PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass->getConstructor()
#15 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(428): PHPStan\Reflection\ClassReflection->findConstructor()
#16 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3301): PHPStan\Reflection\ClassReflection->hasConstructor()
#17 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1119): PHPStan\Analyser\MutatingScope->exactInstantiation()
#18 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(551): PHPStan\Analyser\MutatingScope->resolveType()
#19 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1431): PHPStan\Analyser\MutatingScope->getType()
#20 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2618): PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}()
#21 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1441): PHPStan\Analyser\NodeScopeResolver->processAssignVar()
#22 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(522): PHPStan\Analyser\NodeScopeResolver->processExprNode()
#23 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(323): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#24 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(485): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#25 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(323): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#26 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(569): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#27 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(294): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#28 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(189): PHPStan\Analyser\NodeScopeResolver->processNodes()
#29 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(61): PHPStan\Analyser\FileAnalyser->analyseFile()
#30 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(62): PHPStan\Analyser\Analyser->analyse()
#31 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(141): PHPStan\Command\AnalyserRunner->runAnalyser()
#32 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(66): PHPStan\Command\AnalyseApplication->runAnalyser()
#33 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(180): PHPStan\Command\AnalyseApplication->analyse()
#34 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#35 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_0a43b4828\Symfony\Component\Console\Command\Command->run()
#36 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_0a43b4828\Symfony\Component\Console\Application->doRunCommand()
#37 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_0a43b4828\Symfony\Component\Console\Application->doRun()
#38 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(96): _PHPStan_0a43b4828\Symfony\Component\Console\Application->run()
#39 phar://C:/dvl/Workspace/motiontm/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(97): _PHPStan_0a43b4828\{closure}()
#40 C:\dvl\Workspace\motiontm\vendor-bin\phpstan\vendor\phpstan\phpstan\phpstan(8): require('...')
#41 C:\dvl\Workspace\motiontm\vendor\bin\phpstan(117): include('...')
#42 {main}

the symbols phpstan is not able to find are those which it was able to autoload on 1.6.x with the registered autoloader using bootstrapFiles.

especially interessting is, that when running on xdebug it seems most of the time the autoloading problems are not reproducible.

the autoloader we are using cannot be expressed with simple scanDirectory configs, because of some logic involved (legacy app with certain directory layout requirements)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions