Bug #81542 [NEW]: Class not found using PHPStan and DBAL with opcache enabled

From: Date: Tue, 19 Oct 2021 14:32:41 +0000
Subject: Bug #81542 [NEW]: Class not found using PHPStan and DBAL with opcache enabled
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237283@lists.php.net to get a copy of this message
From:             quadxpies at gmail dot com
Operating system: linux
PHP version:      8.0.11
Package:          opcache
Bug Type:         Bug
Bug description:Class not found using PHPStan and DBAL with opcache enabled

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 bug report at https://bugs.php.net/bug.php?id=81542&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81542&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81542&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81542&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81542&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81542&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81542&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81542&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81542&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81542&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81542&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81542&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81542&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81542&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81542&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81542&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81542&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81542&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#237283) next »