Skip to content

MIR0214

PossiblyNullOperand

An arithmetic or string operation is performed on a value that could be null. Passing null to most operators produces unexpected results or a warning at runtime.

<?php
function divide(?int $a, int $b): float {
return $a / $b; // $a could be null
}

Guard against null before the operation:

<?php
function divide(?int $a, int $b): float {
if ($a === null) {
return 0.0;
}
return $a / $b;
}