Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error: AST failed to parse in located source (first 20 characters: #7590

Closed
kristytoman opened this issue Jul 7, 2022 · 10 comments
Closed

Comments

@kristytoman
Copy link

Bug report

After updating to PHP8.1 I get the

Internal error: Internal error: AST failed to parse in located source (first 20 characters: <?php                                                                                                                                
                                                                                                                                                                                                                                      
     namespace Pha) in file

While running the --debug -vvv mode I get this error

Uncaught PHPStan\BetterReflection\SourceLocator\Ast\Exception\ParseToAstFailure: AST failed to parse in located source (first 20 characters: <?php

namespace Pha) in phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Exception/ParseToAstFailure.php:23
#0 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(57): PHPStan\BetterReflection\SourceLocator\Ast\Exception\ParseToAstFailure::fromLocatedSource()
#1 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(41): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflectionsOfType()
#2 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AbstractSourceLocator.php(45): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflection()
#3 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/PhpVersionBlacklistSourceLocator.php(39): PHPStan\BetterReflection\SourceLocator\Type\AbstractSourceLocator->locateIdentifier()
#4 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28): PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator->locateIdentifier()
#5 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33): PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#6 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32): PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#7 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass()
#8 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(152): PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass()
#9 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(35): PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass()
#10 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(195): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass()
#11 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(146): PHPStan\Rules\FunctionDefinitionCheck->checkParametersAcceptor()
#12 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/ExistingClassesInTypehintsRule.php(43): PHPStan\Rules\FunctionDefinitionCheck->checkClassMethod()
#13 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(105): PHPStan\Rules\Methods\ExistingClassesInTypehintsRule->processNode()
#14 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(95): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#15 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(463): PHPStan\Node\ClassStatementsGatherer->__invoke()
#16 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(326): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#17 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(562): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#18 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(326): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#19 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(534): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#20 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(296): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#21 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(174): PHPStan\Analyser\NodeScopeResolver->processNodes()
#22 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(71): PHPStan\Analyser\FileAnalyser->analyseFile()
#23 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(63): PHPStan\Analyser\Analyser->analyse()
#24 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(207): PHPStan\Command\AnalyserRunner->runAnalyser()
#25 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(100): PHPStan\Command\AnalyseApplication->runAnalyser()
#26 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(168): PHPStan\Command\AnalyseApplication->analyse()
#27 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#28 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_59fb0a3b2\Symfony\Component\Console\Command\Command->run()
#29 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_59fb0a3b2\Symfony\Component\Console\Application->doRunCommand()
#30 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_59fb0a3b2\Symfony\Component\Console\Application->doRun()
#31 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127): _PHPStan_59fb0a3b2\Symfony\Component\Console\Application->run()
#32 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128): _PHPStan_59fb0a3b2\{closure}()
#33 /var/www/project/vendor/phpstan/phpstan/phpstan(8): require('...')
#34 /var/www/project/vendor/bin/phpstan(120): include('...')
#35 {main}
Used memory: 284 MB

Code snippet that reproduces the problem

Was not able to reproduce the problem since the files themselves are fine. There's always 8 of them and even when I tried to delete them it didn't help with this error to appear.

Expected output

Zero internal errors

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

I am very happy with PHPStan otherwise it's a great tool helping us to get better.
This is my first time writing an issue at all so I hope I did it right and that someone will help me with my experience.

Thank you!

@mergeable
Copy link

mergeable bot commented Jul 7, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@kristytoman
Copy link
Author

After some research we found out all the files have one in common and that's \Phalcon\Events\Event in them. It doesn't matter if it's only imported or really used in the class but it always finishes with this internal error.

@ondrejmirtes
Copy link
Member

Hi, thank you for reporting this. I've added a bit more debugging so it should tell us what's the parse error: phpstan/phpstan-src@a342b2b

Can you please update to composer require --dev phpstan/phpstan:1.8.x-dev and re-run PHPStan with --debug? Thanks.

I've also asked for shivammathur/homebrew-extensions#1890 so that I can reproduce and debug it.

@kristytoman
Copy link
Author

Hi, thank you for your response. Here's the output version 1.8.x-dev:

Uncaught PHPStan\BetterReflection\SourceLocator\Ast\Exception\ParseToAstFailure: AST failed to parse in located source (first 20 characters: <?php

namespace Pha) in phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Exception/ParseToAstFailure.php:23
#0 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(57): PHPStan\BetterReflection\SourceLocator\Ast\Exception\ParseToAstFailure::fromLocatedSource()
#1 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(41): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflectionsOfType()
#2 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AbstractSourceLocator.php(45): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflection()
#3 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/PhpVersionBlacklistSourceLocator.php(39): PHPStan\BetterReflection\SourceLocator\Type\AbstractSourceLocator->locateIdentifier()
#4 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28): PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator->locateIdentifier()
#5 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33): PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#6 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32): PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#7 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass()
#8 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(152): PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass()
#9 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(35): PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass()
#10 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(195): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass()
#11 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(146): PHPStan\Rules\FunctionDefinitionCheck->checkParametersAcceptor()
#12 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/ExistingClassesInTypehintsRule.php(43): PHPStan\Rules\FunctionDefinitionCheck->checkClassMethod()
#13 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(105): PHPStan\Rules\Methods\ExistingClassesInTypehintsRule->processNode()
#14 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(95): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#15 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(469): PHPStan\Node\ClassStatementsGatherer->__invoke()
#16 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#17 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(568): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#18 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#19 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(540): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#20 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(302): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#21 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(174): PHPStan\Analyser\NodeScopeResolver->processNodes()
#22 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(71): PHPStan\Analyser\FileAnalyser->analyseFile()
#23 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(63): PHPStan\Analyser\Analyser->analyse()
#24 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(207): PHPStan\Command\AnalyserRunner->runAnalyser()
#25 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(100): PHPStan\Command\AnalyseApplication->runAnalyser()
#26 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(168): PHPStan\Command\AnalyseApplication->analyse()
#27 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#28 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_c6b7ee925\Symfony\Component\Console\Command\Command->run()
#29 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->doRunCommand()
#30 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->doRun()
#31 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->run()
#32 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128): _PHPStan_c6b7ee925\{closure}()
#33 /var/www/project/vendor/phpstan/phpstan/phpstan(8): require('...')
#34 /var/www/project/vendor/bin/phpstan(120): include('...')
#35 {main}

Caused by:
Uncaught PhpParser\Error: Syntax error, unexpected T_NS_SEPARATOR on line 15 on unknown line in phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Parser/PhpParserDecorator.php:33#0 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(54): PHPStan\Parser\PhpParserDecorator->parse()
#1 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Ast/Locator.php(41): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflectionsOfType()
#2 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AbstractSourceLocator.php(45): PHPStan\BetterReflection\SourceLocator\Ast\Locator->findReflection()
#3 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/PhpVersionBlacklistSourceLocator.php(39): PHPStan\BetterReflection\SourceLocator\Type\AbstractSourceLocator->locateIdentifier()
#4 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28): PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator->locateIdentifier()
#5 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33): PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#6 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32): PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#7 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass()
#8 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(152): PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass()
#9 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(35): PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass()
#10 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(195): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass()
#11 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionDefinitionCheck.php(146): PHPStan\Rules\FunctionDefinitionCheck->checkParametersAcceptor()
#12 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/ExistingClassesInTypehintsRule.php(43): PHPStan\Rules\FunctionDefinitionCheck->checkClassMethod()
#13 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(105): PHPStan\Rules\Methods\ExistingClassesInTypehintsRule->processNode()
#14 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(95): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#15 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(469): PHPStan\Node\ClassStatementsGatherer->__invoke()
#16 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#17 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(568): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#18 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#19 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(540): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#20 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(302): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#21 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(174): PHPStan\Analyser\NodeScopeResolver->processNodes()
#22 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(71): PHPStan\Analyser\FileAnalyser->analyseFile()
#23 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(63): PHPStan\Analyser\Analyser->analyse()
#24 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(207): PHPStan\Command\AnalyserRunner->runAnalyser()
#25 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(100): PHPStan\Command\AnalyseApplication->runAnalyser()
#26 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(168): PHPStan\Command\AnalyseApplication->analyse()
#27 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#28 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_c6b7ee925\Symfony\Component\Console\Command\Command->run()
#29 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->doRunCommand()
#30 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->doRun()
#31 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127): _PHPStan_c6b7ee925\Symfony\Component\Console\Application->run()
#32 phar:///var/www/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128): _PHPStan_c6b7ee925\{closure}()
#33 /var/www/project/vendor/phpstan/phpstan/phpstan(8): require('...')
#34 /var/www/project/vendor/bin/phpstan(120): include('...')
#35 {main}
Used memory: 56 MB

@ondrejmirtes
Copy link
Member

This is the root issue. This is how the generated stub for the Event class looks like:

<?php

     namespace Phalcon\Events;

     class Event implements \Phalcon\Events\EventInterface
     {
         protected $cancelable = null;
         protected $data = null;
         protected $source = null;
         protected $stopped = false;
         protected $type = null;
         public function getData()
         {
         }
         public function getSource() : ?\((void*)0)
         {
         }
         public function getType() : string
         {
         }
         public function __construct(string $type, $source = null, $data = null, bool $cancelable =
     \UNKNOWN)
         {
         }
         public function isCancelable() : bool
         {
         }
         public function isStopped() : bool
         {
         }
         public function setData($data = null) : \Phalcon\Events\EventInterface
         {
         }
         public function setType(string $type) : \Phalcon\Events\EventInterface
         {
         }
         public function stop() : \Phalcon\Events\EventInterface
         {
         }
     }

There's a weird return type in the getSource() method which is what throws off the parser.

@ondrejmirtes
Copy link
Member

It's a ReflectionNamedType with name ((void*)0) which isn't valid. I'll make sure to report this to the extension authors.

@ondrejmirtes
Copy link
Member

Reported: phalcon/cphalcon#16023 (comment)

Thank you!

@Jeckerson
Copy link

Jeckerson commented Jul 17, 2022

This is how the generated stub for the Event class looks like:

@ondrejmirtes Could you please tell how did you generate this stub?

@ondrejmirtes
Copy link
Member

@Jeckerson PHPStan uses Roave/BetterReflection, it needs AST to create its Reflection objects. So it reads PHP native Reflection data to generate this source code. It's implemented in ReflectionSourceStubber: https://github.com/ondrejmirtes/BetterReflection/blob/5.3.x/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php

As I said, the return type for the getSource() ReflectionMethod is what the extension reports wrongly.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants