psalm
psalm copied to clipboard
Array destructuring doesn't eliminate null from elements if the right hand is confirmed to be non-null
https://psalm.dev/r/48baf36753
if ([$value] = fetchList())
and while ([$value] = fetchList())
are idioms to run the statement or loop, guaranteeing that the contents won't be null.
I found these snippets:
https://psalm.dev/r/48baf36753
<?php
/**
* @return list{int, int}|null
*/
function returnsList(int $c): ?array {
if ($c) {
return [$c, $c];
}
return null;
}
if ([$a, $b] = returnsList(1)) {
print $a + $b;
}
Psalm output (using commit 4b2c698):
INFO: PossiblyNullOperand - 14:11 - Left operand cannot be nullable, got int|null
INFO: PossiblyNullOperand - 14:16 - Right operand cannot be nullable, got int|null