Skip to content

My code provokes an internal error in phpstan #12949

@mind-bending-forks

Description

@mind-bending-forks

Bug report

Running phpstan 2.1.13 at level 0, with PHP 8.3.6 on Ubuntu 24.04 on a code base, I receive the following:

Internal error: PHPStan\Rules\Variables\DefinedVariableRule::processSingleVariable(): Argument #3 ($variableName) must be of type string, int given, called in                                                                                   
     phar:///…/phpstan.phar/src/Rules/Variables/DefinedVariableRule.php on line 48 while analysing file ….php        
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:

So here is the stack trace:

## phar:///…/phpstan.phar/src/Rules/Variables/DefinedVariableRule.php(55)                                                                                                
     #0 phar:///…/phpstan.phar/src/Rules/Variables/DefinedVariableRule.php(48): PHPStan\Rules\Variables\DefinedVariableRule->processSingleVariable()                          
     #1 phar:///…/phpstan.phar/src/Analyser/FileAnalyser.php(108): PHPStan\Rules\Variables\DefinedVariableRule->processNode()                                                 
     #2 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(767): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()                                           
     #3 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(4003): PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}()                                     
     #4 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(1937): PHPStan\Analyser\NodeScopeResolver->processAssignVar()                                               
     #5 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(766): PHPStan\Analyser\NodeScopeResolver->processExprNode()                                                 
     #6 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(468): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                 
     #7 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(900): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                
     #8 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(468): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                 
     #9 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(796): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                
     #10 phar:///…/phpstan.phar/src/Analyser/NodeScopeResolver.php(416): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                
     #11 phar:///…/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes()                                                        
     #12 phar:///…/phpstan.phar/src/Command/WorkerCommand.php(136): PHPStan\Analyser\FileAnalyser->analyseFile()                                                              
     #13 phar:///…/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): PHPStan\Command\WorkerCommand::PHPStan\Command\{closure}()                         
     #14 phar:///…/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_95d365e52\Evenement\EventEmitter->emit()                                              
     #15 phar:///…/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_95d365e52\Clue\React\NDJson\Decoder->handleData()                         
     #16 phar:///…/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_95d365e52\Evenement\EventEmitter->emit()                                                       
     #17 phar:///…/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_95d365e52\React\Stream\Util::_PHPStan_95d365e52\React\Stream\{closure}()  
     #18 phar:///…/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(168): _PHPStan_95d365e52\Evenement\EventEmitter->emit()                                      
     #19 phar:///…/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_95d365e52\React\Stream\DuplexResourceStream->handleData()                     
     #20 phar:///…/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_95d365e52\React\EventLoop\StreamSelectLoop->waitForStreamActivity()           
     #21 phar:///…/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_95d365e52\React\EventLoop\StreamSelectLoop->run()                                                 
     #22 phar:///…/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                                     
     #23 phar:///…/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_95d365e52\Symfony\Component\Console\Command\Command->run()                              
     #24 phar:///…/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_95d365e52\Symfony\Component\Console\Application->doRunCommand()                         
     #25 phar:///…/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_95d365e52\Symfony\Component\Console\Application->doRun()                                
     #26 phar:///…/phpstan.phar/bin/phpstan(114): _PHPStan_95d365e52\Symfony\Component\Console\Application->run()                                                             
     #27 phar:///…/phpstan.phar/bin/phpstan(115): _PHPStan_95d365e52\{closure}()                                                                                              
     #28 /…/phpstan.phar(6): require('...')                                                                                                                                   
     #29 {main}                                                                                                                                                                                                                                       

(I've obfuscated local paths by replacing them with .)

There's quite possibly something very wrong with the code base (although, superficially, it's running fine), since it has just undergone some major refactoring... An internal phpstan error is still unexpected though.

Code snippet that reproduces the problem

No response

Expected output

phpstan tells me that all sorts of things are wrong with my code.

Did PHPStan help you today? Did it make you happy in any way?

Hopefully phpstan will help me as soon as it stops erroring out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions