rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.71k stars 686 forks source link

running rector with CLI opcache #7912

Closed staabm closed 1 year ago

staabm commented 1 year ago

Bug Report

Subject Details
Rector version e.g. https://github.com/rectorphp/rector/commit/940a47a5805b12ce11d0d74ab6acfbad242b684f

Minimal PHP Code Causing Issue

As soon as I enable opcache cli rector fails and errors.

opcache.enable=1
opcache.enable_cli=1
opcache.file_cache="/tmp/"
opcache.file_cache_only=1
opcache.file_cache_consistency_checks=1
time php bin/rector.php -c rector-test.php --dry-run  -vvv --debug
../phpstan-src/src/Analyser/MutatingScope.php
PHP Fatal error:  Uncaught Error: Class "PHPStan\Node\Expr\OriginalPropertyTypeExpr" not found in phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:2833
Stack trace:
#0 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1521): PHPStan\Analyser\NodeScopeResolver->processAssignVar(Object(PHPStan\Analyser\MutatingScope), Object(PhpParser\Node\Expr\ArrayDimFetch), Object(PhpParser\Node\Expr\StaticCall), Object(Closure), Object(PHPStan\Analyser\ExpressionContext), Object(Closure), true)
#1 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(568): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Expr\Assign), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))
#2 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#3 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(656): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#4 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#5 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(531): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#6 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#7 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(609): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#8 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#9 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(581): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#10 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(331): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#11 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(377): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#12 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(230): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodesWithDependentFiles('/Users/staabm/w...', Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#13 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php(41): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodes(Array, '/Users/staabm/w...')
#14 /Users/staabm/workspace/rector-src/src/Application/FileProcessor.php(34): Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator->decorateNodesFromFile(Object(Rector\Core\ValueObject\Application\File), Array)
#15 /Users/staabm/workspace/rector-src/src/Application/FileProcessor/PhpFileProcessor.php(133): Rector\Core\Application\FileProcessor->parseFileInfoToLocalCache(Object(Rector\Core\ValueObject\Application\File))
#16 /Users/staabm/workspace/rector-src/src/Application/FileProcessor/PhpFileProcessor.php(60): Rector\Core\Application\FileProcessor\PhpFileProcessor->parseFileAndDecorateNodes(Object(Rector\Core\ValueObject\Application\File))
#17 /Users/staabm/workspace/rector-src/src/Application/ApplicationFileProcessor.php(130): Rector\Core\Application\FileProcessor\PhpFileProcessor->process(Object(Rector\Core\ValueObject\Application\File), Object(Rector\Core\ValueObject\Configuration))
#18 /Users/staabm/workspace/rector-src/src/Application/ApplicationFileProcessor.php(85): Rector\Core\Application\ApplicationFileProcessor->processFiles(Array, Object(Rector\Core\ValueObject\Configuration))
#19 /Users/staabm/workspace/rector-src/src/Console/Command/ProcessCommand.php(81): Rector\Core\Application\ApplicationFileProcessor->run(Object(Rector\Core\ValueObject\Configuration), Object(Symfony\Component\Console\Input\ArgvInput))
#20 /Users/staabm/workspace/rector-src/vendor/symfony/console/Command/Command.php(312): Rector\Core\Console\Command\ProcessCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Rector\Core\Console\Command\ProcessCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /Users/staabm/workspace/rector-src/src/Console/ConsoleApplication.php(58): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(168): Rector\Core\Console\ConsoleApplication->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /Users/staabm/workspace/rector-src/bin/rector.php(164): Symfony\Component\Console\Application->run()
#26 {main}
  thrown in phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php on line 2833
Fatal error: Uncaught Error: Class "PHPStan\Node\Expr\OriginalPropertyTypeExpr" not found in phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:2833
Stack trace:
#0 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1521): PHPStan\Analyser\NodeScopeResolver->processAssignVar(Object(PHPStan\Analyser\MutatingScope), Object(PhpParser\Node\Expr\ArrayDimFetch), Object(PhpParser\Node\Expr\StaticCall), Object(Closure), Object(PHPStan\Analyser\ExpressionContext), Object(Closure), true)
#1 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(568): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Expr\Assign), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))
#2 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#3 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(656): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#4 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#5 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(531): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#6 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#7 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(609): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#8 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#9 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(581): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#10 phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(331): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#11 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(377): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#12 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(230): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodesWithDependentFiles('/Users/staabm/w...', Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#13 /Users/staabm/workspace/rector-src/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php(41): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodes(Array, '/Users/staabm/w...')
#14 /Users/staabm/workspace/rector-src/src/Application/FileProcessor.php(34): Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator->decorateNodesFromFile(Object(Rector\Core\ValueObject\Application\File), Array)
#15 /Users/staabm/workspace/rector-src/src/Application/FileProcessor/PhpFileProcessor.php(133): Rector\Core\Application\FileProcessor->parseFileInfoToLocalCache(Object(Rector\Core\ValueObject\Application\File))
#16 /Users/staabm/workspace/rector-src/src/Application/FileProcessor/PhpFileProcessor.php(60): Rector\Core\Application\FileProcessor\PhpFileProcessor->parseFileAndDecorateNodes(Object(Rector\Core\ValueObject\Application\File))
#17 /Users/staabm/workspace/rector-src/src/Application/ApplicationFileProcessor.php(130): Rector\Core\Application\FileProcessor\PhpFileProcessor->process(Object(Rector\Core\ValueObject\Application\File), Object(Rector\Core\ValueObject\Configuration))
#18 /Users/staabm/workspace/rector-src/src/Application/ApplicationFileProcessor.php(85): Rector\Core\Application\ApplicationFileProcessor->processFiles(Array, Object(Rector\Core\ValueObject\Configuration))
#19 /Users/staabm/workspace/rector-src/src/Console/Command/ProcessCommand.php(81): Rector\Core\Application\ApplicationFileProcessor->run(Object(Rector\Core\ValueObject\Configuration), Object(Symfony\Component\Console\Input\ArgvInput))
#20 /Users/staabm/workspace/rector-src/vendor/symfony/console/Command/Command.php(312): Rector\Core\Console\Command\ProcessCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Rector\Core\Console\Command\ProcessCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /Users/staabm/workspace/rector-src/src/Console/ConsoleApplication.php(58): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /Users/staabm/workspace/rector-src/vendor/symfony/console/Application.php(168): Rector\Core\Console\ConsoleApplication->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /Users/staabm/workspace/rector-src/bin/rector.php(164): Symfony\Component\Console\Application->run()
#26 {main}
  thrown in phar:///Users/staabm/workspace/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php on line 2833

As soon as I comment opcache.enable_cli=1 everything works as expected

Expected Behaviour

no errors

TomasVotruba commented 1 year ago

Hi, this might be related to old version of cached custom PHPStan autoloader. Unless we require too old PHPStan version that is missed it :)

The linked Rector version uses PHPStan 1.10.14 - https://github.com/rectorphp/rector/blob/main/composer.json#L11

I check it contains the file you're linking: https://github.com/phpstan/phpstan-src/blob/1.10.14/src/Node/Expr/OriginalPropertyTypeExpr.php

We're unable to debug this here as it's probably related to convention of how opcache works withing phar and composer (no idea, I don't use it). If you find a way to fix it, please send it :+1: