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:10
Avg. Score:4.3 ± 1.0
Reproduced:9 of 9 (100.0%)
Same Version:3 (33.3%)
Same OS:9 (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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: quadxpies at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [2022-11-25 08:13 UTC] schamberumarcelo at gmail dot com
Changed `mediaselectionfield` to also work with enabled translation in tabs ... Added missing attribute accessor methods to `CustomerStream` model.
(https://www.myccpay.vip)github.com
 [2023-01-04 11:40 UTC] Mary548Williams at gmail dot com
Keep it enabled and set opcache.revalidate_freq=0 and restart apache

Or
Put the following somewhere in your laravel application to disable caching for laravel only and only in your debug environment:

if (env('APP_DEBUG')) ini_set('opcache.revalidate_freq', '0');
Maybe you need to change APP_DEBUG to your environment.

(https://www.credible-bh.com/)github.com
 [2023-03-22 14:14 UTC] rohitraj dot bihia at gmail dot com
See also. (https://crediblebhs.online/)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC