Skip to content

Internal error: An optional parameter must have a default value while analysing file #12934

@rx80

Description

@rx80

Bug report

PHP version: PHP 8.4.6
When running phpstan on my project i get an error.
Running the php linter php -l on that particular file doesn't give any errors.

Running phpstan -v gives the following trace:

?:?:Internal error: An optional parameter must have a default value while analysing file Session.php
Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:

phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ArgumentsNormalizer.php(184)

#0 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ArgumentsNormalizer.php(69): PHPStan\Analyser\ArgumentsNormalizer::reorderArgs(Object(PHPStan\Reflection\ResolvedFunctionVariantWithOriginal), Array)
#1 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1720): PHPStan\Analyser\ArgumentsNormalizer::reorderFuncArguments(Object(PHPStan\Reflection\ResolvedFunctionVariantWithOriginal), Object(PhpParser\Node\Expr\FuncCall))
#2 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(593): PHPStan\Analyser\MutatingScope->resolveType('session_set_cookie_params(0, path: \app()->getCookiePath(), secure: true, httponly: true)', Object(PhpParser\Node\Expr\FuncCall))
#3 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1901): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\FuncCall))
#4 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(763): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr(Object(PhpParser\Node\Expr\FuncCall), Object(PHPStan\Analyser\MutatingScope))
#5 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(468): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#6 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(665): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#7 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(468): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#8 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(845): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#9 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(468): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#10 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(796): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#11 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(416): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#12 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#13 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(136): PHPStan\Analyser\FileAnalyser->analyseFile('Session.php', Array, Object(PHPStan\Rules\LazyRegistry), Object(PHPStan\Collectors\Registry), NULL)
#14 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): PHPStan\Command\WorkerCommand::{closure:PHPStan\Command\WorkerCommand::runWorker():117}(Array)
#15 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_db66d83f6\Evenement\EventEmitter->emit('data', Array)
#16 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_db66d83f6\Clue\React\NDJson\Decoder->handleData(Array)
#17 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_db66d83f6\Evenement\EventEmitter->emit('data', Array)
#18 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_db66d83f6\React\Stream\Util::{closure:_PHPStan_db66d83f6\React\Stream\Util::forwardEvents():61}('{"action":"analyse","files":["...')
#19 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(168): _PHPStan_db66d83f6\Evenement\EventEmitter->emit('data', Array)
#20 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_db66d83f6\React\Stream\DuplexResourceStream->handleData(Resource id #7121)
#21 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_db66d83f6\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#22 phar:////vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_db66d83f6\React\EventLoop\StreamSelectLoop->run()
#23 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_db66d83f6\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_db66d83f6\Symfony\Component\Console\Output\ConsoleOutput))
#24 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_db66d83f6\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_db66d83f6\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_db66d83f6\Symfony\Component\Console\Output\ConsoleOutput))
#25 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_db66d83f6\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_db66d83f6\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_db66d83f6\Symfony\Component\Console\Output\ConsoleOutput))
#26 phar:////vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_db66d83f6\Symfony\Component\Console\Application->doRun(Object(_PHPStan_db66d83f6\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_db66d83f6\Symfony\Component\Console\Output\ConsoleOutput))
#27 phar:////vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(114): _PHPStan_db66d83f6\Symfony\Component\Console\Application->run()
#28 phar:////vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(115): {closure:phar:////vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:14}()
#29 //vendor/phpstan/phpstan/phpstan(8): require('phar:////vendor/phpstan/phpstan/phpstan.phar/bin/phpstan')
#30 //vendor/bin/phpstan(119): include('//vendor/phpstan/phpstan/phpstan')
#31 {main}
⚠ Result is incomplete because of severe errors. ⚠
Fix these errors first and then re-run PHPStan
to get all reported errors.

Elapsed time: 15 seconds
Used memory: 2.06 GB

Code snippet that reproduces the problem

No response

Expected output

Expected output is not this error :)

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

No response

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