Skip to content

Internal error thrown when calling json_decode without_arguments #7762

@max11521

Description

@max11521

Bug report

PHPStan throws an internal error when calling json_decode without arguments.

This might be confusing, as the error does not show the number of the line, on which such an error occurs. Moreover, this is a user error, not an internal one, and should be represented as such.

Code snippet that reproduces the problem

<?php
json_decode()

https://phpstan.org/r/c976d447-1984-4ffe-8ffb-ddbcf509921c

Expected output

A normal error, that references the line number, for example something like this:

 ------ ------------------------------------------
  Line   file.php
 ------ ------------------------------------------
  2       json_decode() must be called with at least one argument
 ------ ------------------------------------------

Actual output

Internal error: Internal error: PHPStan\Analyser\MutatingScope::getType(): Argument #1 ($node) must be of type PhpParser\Node\Expr, null given, called in
phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php on line 68 in file
/path/to/project/src/some/path/file.php

Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:
#0 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php(68): PHPStan\Analyser\MutatingScope->getType()
#1 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php(53):
PHPStan\Type\Php\JsonThrowOnErrorDynamicReturnTypeExtension->narrowTypeForJsonDecode()
#2 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1492): PHPStan\Type\Php\JsonThrowOnErrorDynamicReturnTypeExtension->getTypeFromFunctionCall()
#3 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(556): PHPStan\Analyser\MutatingScope->resolveType()
#4 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1422): PHPStan\Analyser\MutatingScope->getType()
#5 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2635): PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}()
#6 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1432): PHPStan\Analyser\NodeScopeResolver->processAssignVar()
#7 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(527): PHPStan\Analyser\NodeScopeResolver->processExprNode()
#8 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#9 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(964): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#10 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#11 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1002): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#12 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(332): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#13 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(605): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#14 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(302): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#15 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(174): PHPStan\Analyser\NodeScopeResolver->processNodes()
#16 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(147): PHPStan\Analyser\FileAnalyser->analyseFile()
#17 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()
#18 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_9a6ded56a\Evenement\EventEmitter->emit()
#19 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_9a6ded56a\Clue\React\NDJson\Decoder->handleData()
#20 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_9a6ded56a\Evenement\EventEmitter->emit()
#21 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):
_PHPStan_9a6ded56a\React\Stream\Util::_PHPStan_9a6ded56a\React\Stream\{closure}()
#22 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_9a6ded56a\Evenement\EventEmitter->emit()
#23 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_9a6ded56a\React\Stream\DuplexResourceStream->handleData()
#24 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_9a6ded56a\React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#25 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(107): _PHPStan_9a6ded56a\React\EventLoop\StreamSelectLoop->run()
#26 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()
#27 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(865): _PHPStan_9a6ded56a\Symfony\Component\Console\Command\Command->run()
#28 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_9a6ded56a\Symfony\Component\Console\Application->doRunCommand()
#29 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_9a6ded56a\Symfony\Component\Console\Application->doRun()
#30 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127): _PHPStan_9a6ded56a\Symfony\Component\Console\Application->run()
#31 phar:///path/to/project/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128): _PHPStan_9a6ded56a\{closure}()
#32 /path/to/project/vendor/phpstan/phpstan/phpstan(8): require('...')
#33 /path/to/project/vendor/bin/phpstan(120): include('...')

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