Source Code:
(back to article)
<?php //To specify a nullable return type, you add a ? before the type function divideNumbers(int $a, int $b): ?float { if ($b === 0) { return null; } return $a / $b; } $result = divideNumbers(10, 2); if ($result !== null) { echo "The result is: " . $result; } else { echo "The division by zero is not allowed."; } ?>
Result:
Report an issue