Hello Hamza,
I think this is something that has been discussed here before.
function types already exist in HackLang: https://docs.hhvm.com/hack/functions/introduction#function-types,
And, if we would follow the same syntax `(function(T, T): T)` or `(callable(T, T): T)`, PHP needs to first support parentheses in
type declaration ( grouping ), which currently it doesn't ( i.e: `function baz((string|bar) $foo): void {}` becomes valid ).
And just to note, function types are also supported by static analysis tools such as Psalm ( https://psalm.dev/docs/annotating_code/type_syntax/callable_types/ ) and PHPStan ( https://phpstan.org/writing-php-code/phpdoc-types#callables ), so i suppose if PHP is to support typed callables, it should take inspiration from these tools.
There's also an alternative syntax that was proposed back in 2016 for PHP 7.1, but it seems like the RFC was abandoned: https://wiki.php.net/rfc/typesafe-callable
Cheers,
Saif.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, April 7, 2021 11:58 AM, Hamza Ahmad <office.hamzaahmad@gmail.com> wrote: