Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Error: Call to a member function loadClass() on int #7150

Closed
Wirone opened this issue Apr 28, 2022 · 20 comments
Closed

Internal Error: Call to a member function loadClass() on int #7150

Wirone opened this issue Apr 28, 2022 · 20 comments
Labels

Comments

@Wirone
Copy link
Contributor

Wirone commented Apr 28, 2022

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 🎉

@mergeable
Copy link

mergeable bot commented Apr 28, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

I'm a little bit baffled by this error. Could you please replicate that in a small repository? Thanks.

@Wirone
Copy link
Contributor Author

Wirone commented Apr 29, 2022

I'm not sure if it's possible. We have custom directory structure, custom app architecture, custom autoloader, custom bootstrap, custom PHPStan runtime config... I don't know if I can extract what's required to reproduce it (like in rectorphp/rector#7135). I'll work on it today and try to investigate further.

@stof
Copy link
Contributor

stof commented Apr 29, 2022

Looking at the stack trace, this seems to happen inside a class_exists check. So I suspect that the error actually happens in one of the autoloaders registered in your project rather than in phpstan itself.

@Wirone
Copy link
Contributor Author

Wirone commented Apr 29, 2022

@stof but it works properly without bleeding edge enabled, with the same architecture, file structure, analysis range and configs. Hence this issue, because it's strictly related to changing PHPStan config.

@ondrejmirtes
Copy link
Member

I guess the custom autoloader is somehow causing this mess 😊 Try to use scanDirectories to find the classes instead. https://phpstan.org/user-guide/discovering-symbols

@Wirone
Copy link
Contributor Author

Wirone commented Apr 29, 2022

@ondrejmirtes scanDirectories did not work, but I was able to get rid of this error by adding require_once $rootDir . '/vendor/rector/rector/src/Rector/AbstractRector.php'; in our bootstrap file. I don't understand why, since this class is within Composer's autoloader which is included at the top of the bootstrap. I can't investigate it further right now, but if you think it's not a PHPStan's bug feel free to close 🙂

CC: @TomasVotruba

@ondrejmirtes
Copy link
Member

I'd like to see what your custom autoloaders do to understand this problem.

@TomasVotruba
Copy link

@Wirone Reproducible repository would be indeed the most helpful :)

@Wirone
Copy link
Contributor Author

Wirone commented Apr 29, 2022

@ondrejmirtes @TomasVotruba I'll try create something (after May 3rd, got holidays 🌴 ), but it won't be easy and I can't promise anything 😅

@ondrejmirtes
Copy link
Member

@Wirone An idea - does your problem happen when you disable OPCache?

@luxemate
Copy link

luxemate commented May 3, 2022

@ondrejmirtes @TomasVotruba I have exactly the same problem, and it's also related to a Rector rule.

Internal error: Internal error: Call to a member function loadClass() on int in file
/app/src/Crassula/Util/Rector/Rule/ImportPhpUnitFunctionsRector.php

Turning off the disableRuntimeReflectionProvider feature toggle from bleedingEdge.neon config does the trick, and the error dissapears.

PS. I don't have any custom autoloaders.

@ondrejmirtes
Copy link
Member

@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.

@luxemate
Copy link

luxemate commented May 4, 2022

@ondrejmirtes Sure. https://github.com/luxemate/phpstan-rector-error

@Wirone
Copy link
Contributor Author

Wirone commented May 4, 2022

@Wirone An idea - does your problem happen when you disable OPCache?

FYI: it was already discussed on Slack. I've tested with dev-main and without OPCache and error was there anyway. I'm back after vacation and will revisit those issues, but I need some time to handle all the stacked tasks.

PS. Thank you @luxemate for the reproducer 👍

@ondrejmirtes
Copy link
Member

Reproduced: 047f3d8
And fixed: phpstan/phpstan-src@46f51e7

@ondrejmirtes
Copy link
Member

Please test PHPStan 1.6.5 with this fix https://github.com/phpstan/phpstan/releases/tag/1.6.5

@luxemate
Copy link

luxemate commented May 4, 2022

@ondrejmirtes I've tested - it works. Thank you and have a great day!

@Wirone
Copy link
Contributor Author

Wirone commented May 4, 2022

It looks like 1.6.5 fixed the issue for us too 🎉 I was able to remove temporary workaround with explicit autoload rule. Thank tou @ondrejmirtes 🍻

@github-actions
Copy link

github-actions bot commented Jun 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants