If the signature says the callable needs to return a type, an invocation of said callable must always return an instance of that type.
typedef returns_int = callable(string $in): int ;
function foo(returns_int $cb) {
return $cb("123");
}
// This is a closure that returns int
$fn = fn($a) => "4$a";
// This is using the closure.
$result = foo($fn);
In strict mode, this should be an error. In weak mode type juggling could occur.
But adding return type info to closures seems unlikely to be possible.
In strict mode, this should be an error. In weak mode type juggling could occur.
But adding return type info to closures seems unlikely to be possible.