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

Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, null given #5525

Closed
bram-pkg opened this issue Aug 24, 2021 · 5 comments

Comments

@bram-pkg
Copy link

bram-pkg commented Aug 24, 2021

Bug report

PHPstan crashes before analysis starts. No point in making a reproduction link for this.

I'm running PHP 8.0.9 and PHPstan 0.12.96

Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, null given 
Click to show stacktrace!
Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, null given in phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/
OptimizedDirectorySourceLocator.php:168
#0 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php(168): preg_replace()
#1 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php(133): PHPStan\Reflection\BetterReflection\SourceLocator\Optimize
dDirectorySourceLocator->findSymbols()
#2 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php(118): PHPStan\Reflection\BetterReflection\SourceLocator\Optimize
dDirectorySourceLocator->init()
#3 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php(68): PHPStan\Reflection\BetterReflection\SourceLocator\Optimized
DirectorySourceLocator->findFilesByFunction()
#4 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(31): PHPStan\Reflection\BetterReflection\SourceLocator\Opt
imizedDirectorySourceLocator->locateIdentifier()
#5 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(31): PHPStan\BetterReflection\SourceLocator\Type\Aggregate
SourceLocator->locateIdentifier()
#6 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/FunctionReflector.php(34): PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator-
>locateIdentifier()
#7 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingFunctionReflector.php(29): PHPStan\BetterReflection\Reflector\FunctionReflector->reflect()
#8 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/SignatureMap/NativeFunctionReflectionProvider.php(92): PHPStan\Reflection\BetterReflection\Reflector\MemoizingFunctionReflector->re
flect()
#9 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Runtime/RuntimeReflectionProvider.php(166): PHPStan\Reflection\SignatureMap\NativeFunctionReflectionProvider->findFunctionReflectio
n()
#10 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php(123): PHPStan\Reflection\Runtime\RuntimeReflectionProvider->getFunction()
#11 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/ChainReflectionProvider.php(88): PHPStan\Reflection\ReflectionProvider\ClassBlacklistReflectionProvider->getFun
ction()
#12 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(63): PHPStan\Reflection\ReflectionProvider\ChainReflectionProvider->getFunction
()
#13 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1552): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->getFunction()
#14 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(441): PHPStan\Analyser\MutatingScope->resolveType()
#15 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(697): PHPStan\Analyser\MutatingScope->getType()
#16 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(441): PHPStan\Analyser\MutatingScope->resolveType()
#17 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1344): PHPStan\Analyser\MutatingScope->getType()
#18 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(459): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()
#19 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(258): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#20 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(423): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#21 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(258): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#22 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(507): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#23 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(258): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#24 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(473): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#25 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(226): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#26 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(149): PHPStan\Analyser\NodeScopeResolver->processNodes()
#27 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(52): PHPStan\Analyser\FileAnalyser->analyseFile()
#28 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(56): PHPStan\Analyser\Analyser->analyse()
#29 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(148): PHPStan\Command\AnalyserRunner->runAnalyser()
#30 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(79): PHPStan\Command\AnalyseApplication->runAnalyser()
#31 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(157): PHPStan\Command\AnalyseApplication->analyse()
#32 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(228): PHPStan\Command\AnalyseCommand->execute()
#33 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856): _PHPStan_68495e8a9\Symfony\Component\Console\Command\Command->run()
#34 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(237): _PHPStan_68495e8a9\Symfony\Component\Console\Application->doRunCommand()
#35 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(138): _PHPStan_68495e8a9\Symfony\Component\Console\Application->doRun()
#36 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(82): _PHPStan_68495e8a9\Symfony\Component\Console\Application->run()
#37 phar:///home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(83): _PHPStan_68495e8a9\{closure}()
#38 /home/bram/src/Faker/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan(8): require('...')
#39 {main}

Code snippet that reproduces the problem

Not applicable since PHPstan crashes before analysing files.

Expected output

Static code analysis of the code base.

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

Not today but it has helped me catch a lot of type errors in one of my projects!

@mergeable
Copy link

mergeable bot commented Aug 24, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Would be great to create a small reproducing repository that shows the problem, thank you.

@bram-pkg
Copy link
Author

bram-pkg commented Aug 24, 2021

The project I am experiencing this error on is https://github.com/FakerPHP/Faker

@ondrejmirtes
Copy link
Member

Temporary fix until someone comes up with a better regex: phpstan/phpstan-src@a09a98d (this one fails with "backtrack limit exhausted")

@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 Sep 26, 2021
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

2 participants