Skip to content

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

@internalsystemerror

Description

@internalsystemerror

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions