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
- Change after https://github.com/phpstan/phpstan/issues/5866 — committed to dpi/dogit by dpi 2 years ago
- Update phpstan/phpstan requirement from 1.6.8 to 1.7.1 (#72) * Update phpstan/phpstan requirement from 1.6.8 to 1.7.1 Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpst... — committed to dpi/dogit by dependabot[bot] 2 years ago
I will try to fix it
Fixed: https://github.com/phpstan/phpstan-src/pull/1301