1.2.872. Nullable Without Check¶
Nullable typed argument or properties should be checked before usage. When they are null, they probably won’t behave like the other type, and lead to an error.
<?php
// This will emit a fatal error when $a = null
function foo(?A $a) {
return $a->m();
}
// This is stable
function foo(?A $a) {
if ($a === null) {
return 42;
} else {
return $a->m();
}
}
?>
See also Null Return Types.
1.2.872.1. Connex PHP features¶
1.2.872.1.1. Suggestions¶
Add a check on return value
1.2.872.1.2. Specs¶
Short name |
Functions/NullableWithoutCheck |
Rulesets |
|
Exakat since |
2.0.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |