php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81542 Class not found using PHPStan and DBAL with opcache enabled
Submitted: 2021-10-19 14:32 UTC Modified: 2021-10-19 17:35 UTC
Votes:8
Avg. Score:4.1 ± 1.1
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:7 (100.0%)
From: quadxpies at gmail dot com Assigned:
Status: Open Package: opcache
PHP Version: 8.0.11 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-10-19 14:32 UTC] 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}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-19 14:54 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 08:03:35 2021 UTC