Closed pilec closed 6 years ago
That's intentional, analyzer can't do assumptions recursively. If you put the check directly into the code, it will be ok. The same way it would work in other typed languages.
e.g. Kotlin
fun test(): Int {
val a: Int? = null
check(a)
return a
}
fun check(a: Int?) {
if (a == null) {
throw NullPointerException()
}
}
One solution is to introduce null (false) filter function. When generics will be introduced, you could have a general one then.
Other solution is do an assert manually.
$this->check($user);
assert($user instanceof User);
which is quite similar to !!
operator in Kotlin
check(a)
a!!
Hi, this is a duplicate of #201, please see the discussion there (and other issues linked in the milestone as well).
Ah, you are right! Sorry for inconvenience, I tried to find similar issue and failed.
https://phpstan.org/r/796b65022c2cccf0d86a95d2a4754b6f
Especially annoying with Dibi. Can be solved by workaround: