[RFC] Callable Types
| From: | Marcio Almada | Date: | Sat, 23 Apr 2016 18:22:04 +0000 |
| Subject: | [RFC] Callable Types | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-92664@lists.php.net to get a copy of this message | ||
Redirecting this to the list as this message was sent privately probably by
accident :)
---------- Forwarded message ----------
From: Mathieu Rochette <mathieu@texthtml.net>
Date: 2016-04-23 12:44 GMT-04:00
Subject: Re: [PHP-DEV][RFC] Callable Types
To: Marcio Almada <marcio.web2@gmail.com>
On 04/22/2016 06:12 AM, Marcio Almada wrote:
Hello everyone,
We just completed the draft for the "Callable Types" RFC. This RFC has been
recently mentioned during other type related threads on this mailing list,
so it feels to be the right time to put the proposal in context:
The proposal is at https://wiki.php.net/rfc/callable-types
It looks very nice overall :) and would be, imho, a great addition to PHP
I have a few comments, first about the optional arguments, the example in
the rfc says :
> // That means that foo() could call $cb and pass anything as a first
argument and if it would be something that is not an instance of A the call
would fail.
I don't get why foo would be declared as
function foo(callable() $cb) { }
instead of
function foo(callable($any) $cb) { }
if foo intends to call $cb with an argument.
what about optional arguments, eg:
class Foo
{
private $logger;
public __construct(Logger $logger = null) {$this->logger = $logger;}
public doSomething(callable(int $done, int $remaining, Logger = null)
$progressCb) {
// ...
for($i = 0; $i < $n; $i++) {
// ...
$progressCb($i, $n - $i, $this->logger);
}
}
}
should that be supported ?
and last one, will instanceof supports this new syntax?
thank you
The W.I.P patch is available for testing through http://3v4l.org under
the
RFC tab.
We count with your detailed feedback and insights. Let's have a nice,
respectful and
constructive conversation about the RFC and work on possible improvements!
Thanks
Nikita Nefedov
Márcio Almada
--
Mathieu Rochette