Bug #81542 [Opn]: Class not found using PHPStan and DBAL with opcache enabled
Edit report at https://bugs.php.net/bug.php?id=81542&edit=1
ID: 81542
Updated by: nikic@php.net
Reported by: quadxpies at gmail dot com
Summary: Class not found using PHPStan and DBAL with opcache
enabled
Status: Open
Type: Bug
Package: opcache
Operating System: linux
PHP Version: 8.0.11
Block user comment: N
Private report: N
New Comment:
This also happens with opcache.jit=0 and opcache.optimization_level=0, so this is very likely
related to the stream wrapper magic that phpstan has going on. I don't plan to look into this
without a reduction.
Previous Comments:
------------------------------------------------------------------------
[2021-10-19 14:32:41] quadxpies at gmail dot com
Description:
------------
Running PHPStan analysis with opcache.enable_cli=1 on below file produces 'Class
"Doctrine\DBAL\ParameterType" not found error':
<?php
$connection = \Doctrine\DBAL\DriverManager::getConnection([]);
$stmt = $connection->prepare('');
$stmt->bindValue('', '', \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
No error is reported when opcache is disabled.
PHP 7.4 is not affected.
Error is also not reported when "use" is added:
use Doctrine\DBAL\ParameterType;
More info:
https://github.com/phpstan/phpstan/issues/5806
https://github.com/phpstan/phpstan/issues/5173
Test script:
---------------
docker run --rm -it bitnami/php-fpm:8.0 bash
composer require doctrine/dbal ^2 phpstan/phpstan
cat <<EOT > index.php
<?php
\$connection = \Doctrine\DBAL\DriverManager::getConnection([]);
\$stmt = \$connection->prepare('');
\$stmt->bindValue('', '', \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
EOT
php -d opcache.enable_cli=1 vendor/bin/phpstan analyse index.php
Expected result:
----------------
[OK] No errors
Actual result:
--------------
------ ----------------------------------------------------------------------
Line index.php
------ ----------------------------------------------------------------------
Internal error: Class "Doctrine\DBAL\ParameterType" not found
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
------ ----------------------------------------------------------------------
[ERROR] Found 1 error
Stack trace:
Uncaught Error: Class "Doctrine\DBAL\ParameterType" not found in
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassConstantReflection.php:57
#0 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassConstantReflection.php(57):
ReflectionClassConstant->getValue()
#1 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1479):
PHPStan\Reflection\ClassConstantReflection->getValue()
#2 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(443):
PHPStan\Analyser\MutatingScope->resolveType()
#3
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ParametersAcceptorSelector.php(84):
PHPStan\Analyser\MutatingScope->getType()
#4 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3294):
PHPStan\Reflection\ParametersAcceptorSelector::selectFromArgs()
#5 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1526):
PHPStan\Analyser\MutatingScope->methodCallReturnType()
#6 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1532):
PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()
#7 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(443):
PHPStan\Analyser\MutatingScope->resolveType()
#8 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1345):
PHPStan\Analyser\MutatingScope->getType()
#9 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(460):
PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()
#10 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(227):
PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#11 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(149):
PHPStan\Analyser\NodeScopeResolver->processNodes()
#12 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(52):
PHPStan\Analyser\FileAnalyser->analyseFile()
#13 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(56):
PHPStan\Analyser\Analyser->analyse()
#14 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(148):
PHPStan\Command\AnalyserRunner->runAnalyser()
#15 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(79):
PHPStan\Command\AnalyseApplication->runAnalyser()
#16 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(157):
PHPStan\Command\AnalyseApplication->analyse()
#17 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(228):
PHPStan\Command\AnalyseCommand->execute()
#18 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856):
_PHPStan_76800bfb5\Symfony\Component\Console\Command\Command->run()
#19 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(237):
_PHPStan_76800bfb5\Symfony\Component\Console\Application->doRunCommand()
#20 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(138):
_PHPStan_76800bfb5\Symfony\Component\Console\Application->doRun()
#21 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(82):
_PHPStan_76800bfb5\Symfony\Component\Console\Application->run()
#22 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(83): _PHPStan_76800bfb5\{closure}()
#23 /app/vendor/phpstan/phpstan/phpstan(8): require('...')
#24 {main}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81542&edit=1
Thread (6 messages)