phpstan: Internal Error: Call to a member function `loadClass()` on `int`
Bug report
After upgrading to 1.6.3 and enabling bleeding edge rules, we got this error when analysing one of our areas.
Code snippet that reproduces the problem
I don’t know what exactly is causing the issue, but probably something related to bootstrap and autoloading. The -v stacktrace:
Internal error: Internal error: Call to a member function loadClass() on int in file /app/utils/rector/sets/legacy-code.php
Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:
#0 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(281): {closure}('Rector\\Config\\R...')
#1 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php(61):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator::PHPStan\Reflection\BetterReflection\SourceLocator\{closure}()
#2 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(293):
PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::withStreamWrapperOverride(Object(Closure))
#3 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(116):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateClassByName('Rector\\Config\\R...')
#4 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))
#5 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33):
PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))
#6 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32):
PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))
#7 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45):
PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass('Rector\\Config\\R...')
#8 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(146):
PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass('Rector\\Config\\R...')
#9 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(34):
PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass('Rector\\Config\\R...')
#10 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Rules/ClassCaseSensitivityCheck.php(34): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass('Rector\\Config\\R...')
#11 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Namespaces/ExistingNamesInUseRule.php(107): PHPStan\Rules\ClassCaseSensitivityCheck->checkClassNames(Array)
#12 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Namespaces/ExistingNamesInUseRule.php(61): PHPStan\Rules\Namespaces\ExistingNamesInUseRule->checkClasses(Array)
#13 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(102): PHPStan\Rules\Namespaces\ExistingNamesInUseRule->processNode(Object(PhpParser\Node\Stmt\Use_),
Object(PHPStan\Analyser\MutatingScope))
#14 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(369): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Use_),
Object(PHPStan\Analyser\MutatingScope))
#15 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(314): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Use_),
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#16 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(526): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array,
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#17 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(285): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_),
Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#18 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(189): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#19 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(143): PHPStan\Analyser\FileAnalyser->analyseFile('/Volumes/Projec...', Array, Object(PHPStan\Rules\Registry), NULL)
#20 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)
#21 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_c900ee2af\Evenement\EventEmitter->emit('data', Array)
#22 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_c900ee2af\Clue\React\NDJson\Decoder->handleData(Array)
#23 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_c900ee2af\Evenement\EventEmitter->emit('data', Array)
#24 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):
_PHPStan_c900ee2af\React\Stream\Util::_PHPStan_c900ee2af\React\Stream\{closure}('{"action":"anal...')
#25 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_c900ee2af\Evenement\EventEmitter->emit('data', Array)
#26 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_c900ee2af\React\Stream\DuplexResourceStream->handleData(Resource id #11547)
#27 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_c900ee2af\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#28 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(106): _PHPStan_c900ee2af\React\EventLoop\StreamSelectLoop->run()
#29 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_c900ee2af\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_c900ee2af\Symfony\Component\Console\Output\ConsoleOutput))
#30 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856):
_PHPStan_c900ee2af\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_c900ee2af\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_c900ee2af\Symfony\Component\Console\Output\ConsoleOutput))
#31 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_c900ee2af\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand),
Object(_PHPStan_c900ee2af\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_c900ee2af\Symfony\Component\Console\Output\ConsoleOutput))
#32 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):
_PHPStan_c900ee2af\Symfony\Component\Console\Application->doRun(Object(_PHPStan_c900ee2af\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_c900ee2af\Symfony\Component\Console\Output\ConsoleOutput))
#33 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(96): _PHPStan_c900ee2af\Symfony\Component\Console\Application->run()
#34 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(97): _PHPStan_c900ee2af\{closure}()
#35 /app/vendor/phpstan/phpstan/phpstan(7): require('phar:///Volumes...')
#36 /app/vendor/bin/phpstan(112): include('/Volumes/Projec...')
#37 {main}
Internal error: Internal error: Call to a member function loadClass() on int in file /app/utils/rector/src/AppRectorSets.php
app/utils/rector/src/AppRectorSets.php:
<?php
declare(strict_types=1);
namespace App\Utils\Rector;
use Rector\Set\Contract\SetListInterface;
final class AppRectorSets implements SetListInterface
{
public const LEGACY_CODE = __DIR__ . '/../sets/legacy-code.php';
}
In composer.json we have:
{
"autoload-dev": {
"psr-4": {
"App\\Utils\\Rector\\": "utils/rector/src",
}
}
}
FYI: I’ve masked actual namespace and filenames, but it’s as close as it can be to the original.
Expected output
No internal error
Did PHPStan help you today? Did it make you happy in any way?
Bleeding edge rules allowed me to find some dead code in one class 🎉
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (14 by maintainers)
@ondrejmirtes Sure. https://github.com/luxemate/phpstan-rector-error
Reproduced: https://github.com/phpstan/phpstan/commit/047f3d86416ae160a1ee641e3cd77a7f824f66ef And fixed: https://github.com/phpstan/phpstan-src/commit/46f51e71c32b79313e36e6fd26fba94e6e8c70db
@luxemate Can you please reproduce that in a small repository? No one with this problem actually got around to it yet so I can’t look into it.