The closure/anonymous function is missing the native return type declaration. Native return type can help enforce type, which can lead to more readable, reliable code. They ensure that the value is of the specified type at call time, otherwise a TypeError is thrown.
function () { // missing native return type declaration
return 'Hello there!';
};
function (bool $bool) { // missing native return type declaration
if ($bool) {
return;
} else {
return 1;
}
};
function (): string {
return 'Hello there!';
};
function (bool $bool): ?int {
if ($bool) {
return;
} else {
return 1;
}
};