On Tue, 11 Feb 2020 at 13:19, Nikita Popov <nikita....@gmail.com> wrote:
>
> https://wiki.php.net/rfc/consistent_callables.
>

btw it's probably worth mentioning the other reason I didn't pursue
https://wiki.php.net/rfc/consistent_callables.

By itself, the callable type isn't much use. It only allows you to
specify that a type can be called, but it doesn't allow you to specify
what parameters the callable should take, or what the return type
should be.

Just making the callable type be consistent would be a lot of work,
and possibly cause a lot of BC breaks and still not do the useful
thing.

Instead what would be far more useful would be allow people to define
the callable signature, and use that as a type.

callable some_callback(int $x, string $y) : int;

function bar(some_callback $fn) {  }

$fn_correct = function (int $x, string $y) : int {}
$fn_wrong = function (int $x, string $y) : int {}

Calling bar with $fn_correct should work.
Calling bar with $fn_wrong should give a type error.

In my opinion, pursuing that idea would be a lot more valuable than
breaking BC for callables without much gain.

cheers
Dan
Ack

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to