Skip to content

phpstan requires ext-simplexml to be installed #9714

@SomeBdyElse

Description

@SomeBdyElse

Bug report

In our local dev environment, phpstan requires ext-simplexml to be installed to analyze code with the SimpleXMLElement constructor. The on-line PHPStan playground does it correctly. Locally, we get the following stack trace:

0bfe5f978e66:/app# ./vendor/bin/phpstan --version
PHPStan - PHP Static Analysis Tool 1.10.26
0bfe5f978e66:/app# ./vendor/bin/phpstan analyse -v --memory-limit=2G
Note: Using configuration file /app/phpstan.neon.
 319/319 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 2 secs

 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Error                                                                                                                                                                          
 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Internal error: Internal error: Class "SimpleXMLElement" not found in file /app/src/…/Classes/Command/AbstractCommand.php                                      
                                                                                                                                                                                    
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:                                                                      
     #0 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2550):                                                                                   
     PHPStan\Type\Php\SimpleXMLElementConstructorThrowTypeExtension->getThrowTypeFromStaticMethodCall()                                                                             
     #1 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2180): PHPStan\Analyser\NodeScopeResolver->getConstructorThrowPoint()                    
     #2 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1585): PHPStan\Analyser\NodeScopeResolver->processExprNode()                             
     #3 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2930): PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}()                  
     #4 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1593): PHPStan\Analyser\NodeScopeResolver->processAssignVar()                            
     #5 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(599): PHPStan\Analyser\NodeScopeResolver->processExprNode()                              
     #6 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                              
     #7 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(557): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                             
     #8 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                              
     #9 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(640): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                             
     #10 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                             
     #11 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(612): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                            
     #12 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(353): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                             
     #13 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(173): PHPStan\Analyser\NodeScopeResolver->processNodes()                                     
     #14 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(130): PHPStan\Analyser\FileAnalyser->analyseFile()                                           
     #15 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                                        
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()                                                                                                                     
     #16 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_d55c4f2c2\Evenement\EventEmitter->emit()                           
     #17 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                                        
     _PHPStan_d55c4f2c2\Clue\React\NDJson\Decoder->handleData()                                                                                                                     
     #18 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_d55c4f2c2\Evenement\EventEmitter->emit()                                    
     #19 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                                        
     _PHPStan_d55c4f2c2\React\Stream\Util::_PHPStan_d55c4f2c2\React\Stream\{closure}()                                                                                              
     #20 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_d55c4f2c2\Evenement\EventEmitter->emit()                   
     #21 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_d55c4f2c2\React\Stream\DuplexResourceStream->handleData()  
     #22 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):                                                                     
     _PHPStan_d55c4f2c2\React\EventLoop\StreamSelectLoop->waitForStreamActivity()                                                                                                   
     #23 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_d55c4f2c2\React\EventLoop\StreamSelectLoop->run()                              
     #24 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                  
     #25 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_d55c4f2c2\Symfony\Component\Console\Command\Command->run()           
     #26 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_d55c4f2c2\Symfony\Component\Console\Application->doRunCommand()      
     #27 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_d55c4f2c2\Symfony\Component\Console\Application->doRun()             
     #28 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_d55c4f2c2\Symfony\Component\Console\Application->run()                                          
     #29 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_d55c4f2c2\{closure}()                                                                           
     #30 /app/vendor/phpstan/phpstan/phpstan(8): require('...')                                                                                                                     
     #31 /app/vendor/bin/phpstan(117): include('...')                                                                                                                               
     #32 {main}                                                                                                                                                                     
     Child process error (exit code 1):   

Once we install php81-simplexml, phpstan misses the obvious type error shown in the playground example and passes the file without complaint. This seems incorrect, as the example contains a type error.

Code snippet that reproduces the problem

https://phpstan.org/r/a523934f-ea45-45f1-98fb-5691c4afb358

Expected output

phpstan should complain about the error, as it does in the playground.

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

It makes our code better :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions