Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing null inspection when attempting to access ::class #1952

Open
chriscpty opened this issue Aug 20, 2024 · 0 comments
Open

Missing null inspection when attempting to access ::class #1952

chriscpty opened this issue Aug 20, 2024 · 0 comments

Comments

@chriscpty
Copy link

Subject Details
Plugin Php Inspections (EA Extended)
Language level PHP 8.1

Current behaviour

Attempting to access $foo::class on a potentially null $foo does not throw a warning, despite this throwing a null error if $foo is null.

A side effect of this, and where i first noticed the issue, is that the warning gets misplaced in match calls:

$baz = match ($foo::class) { // no null warning here
    Foo::class => $foo->foo(), // null warning occurs here instead
    Bar::class => $foo->bar(), // and here
    default => []
};

Expected behaviour

Attempting to access $foo::class when $foo may be null should be marked as "Null pointer exception may occur here".
Thus, in the match example above, the warning should not occur in the match arms because they aren't reachable if $foo is null.

Environment details

PHPStorm Build #PS-242.20224.361, built on August 10, 2024
Runtime version: 21.0.3+13-b509.4 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant