Skip to content

Commit

Permalink
Fix internal error with json_decode() without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 9, 2022
1 parent 8ab002a commit bf6d4c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php
Expand Up @@ -77,6 +77,9 @@ private function narrowTypeForJsonDecode(FuncCall $funcCall, Scope $scope, Type
{
$args = $funcCall->getArgs();
$isArrayWithoutStdClass = $this->isForceArrayWithoutStdClass($funcCall, $scope);
if (!isset($args[0])) {
return $fallbackType;
}

$firstValueType = $scope->getType($args[0]->value);
if ($firstValueType instanceof ConstantStringType) {
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Expand Up @@ -890,6 +890,14 @@ public function testBug7737(): void
$this->assertNoErrors($errors);
}

public function testBug7762(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7762.php');
$this->assertCount(2, $errors);
$this->assertSame('Function json_decode invoked with 0 parameters, 1-4 required.', $errors[0]->getMessage());
$this->assertSame('Function json_encode invoked with 0 parameters, 1-3 required.', $errors[1]->getMessage());
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7762.php
@@ -0,0 +1,6 @@
<?php

namespace Bug7762;

json_decode();
json_encode();

0 comments on commit bf6d4c0

Please sign in to comment.