Open Simbiat opened 4 months ago
Similar example in a match
statement:
function foo (?SomeEnum $bar) {
match ($bar) {
null => 'invalid',
SomeEnum::SomeCase => $bar->value,
};
}
Accessing $bar->value
gets an inspection flag. However, the null
case is evaluated first, making it impossible for $bar
to be null
in the second case.
PhpStorm 2024.2 EAP
Build #PS-242.10180.24, built on May 14, 2024
Runtime version: 21.0.3+13-b446.1 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 12
Registry:
debugger.new.tool.window.layout=true
run.processes.with.pty=TRUE
ide.experimental.ui=true
I have similiar problem in ternary operator usage...
PhpStorm 2024.1.4 Build #PS-241.18034.69, built on June 21, 2024 Runtime version: 17.0.11+1-b1207.24 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
i think this can be generalised as a false positive whenever the check for null is done indirectly (so not something along the lines of $foo !== null
or empty($foo)
).
If the null/empty check instead checks for one of $foo
s attributes (through ?->
or similar), the inspection doesn't pick up on it.
I think @jtheuerkauf 's match
error is a separate issue?
Current behaviour
Have a DOMNode element and code like this
Get null pointer exception warning
Expected behaviour
No warning, since there is is a null safe operator
?->
used for the same object.Environment details