phpstan: False Positive: Dead Catch for JsonException when using PHP 8 named parameters

Bug report

When using PHP 8 named parameters, a false Dead Catch warning appears e.g.

try {
    $parsed = json_decode($contents, true, flags: JSON_BIGINT_AS_STRING | JSON_OBJECT_AS_ARRAY | JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
    throw new InvalidArgumentException('Unable to decode contents');
}

results in the error: Dead catch - JsonException is never thrown in the try block.

Code snippet that reproduces the problem

https://phpstan.org/r/35f161ee-735a-4e62-ad36-0fd22b255300

Expected output

No errors

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

I haven’t been able to not use this tool since I first started way back when.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments