Skip to content

Nullsafe operator false negatives - RuleLevelHelper::findTypeToCheck used in places where NULL removal is not desired #5687

@olsavmic

Description

@olsavmic

Bug report

This issue is directly related to phpstan/phpstan-strict-rules#135, which is actually the main issue for us.

The logic introduced in phpstan/phpstan-src@75d00c9
always removes NULL value from the final type in case of null-safe access.

That makes sense for some rules like CallMethodsRule but in cases that care about the actual return value, this assumption is wrong.

Code snippet that reproduces the problem

https://phpstan.org/r/82a28570-e464-4010-91a0-683a22605bb8

Expected output

Cannot use array destructuring on null.

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

😍 PHPStan is awesome! Can't imagine using PHP without static type checking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions