hi!

From: Mathieu Rochette <math...@texthtml.net>
> Date: 2016-04-23 12:44 GMT-04:00
> Subject: Re: [PHP-DEV][RFC] Callable Types
>
>
> 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 ?
>
>
Currently you can nullify or skip the Logger argument upon implementation
of the callable. Rendering your example:

https://3v4l.org/qb5QR/rfc#tabs

Admittedly, the expectation for default values to work seems legit and we
are currently discussing whether to support
default values on callable types signatures or not (inclined to do not
support). But honestly I haven't seen a legit use
case when we already have the ability to satisfy the callback with a
smaller type. Perhaps you may have one use case
where a default value would be indispensable?


>
> and last one, will instanceof supports this new syntax?
>
>

Yes, please expect to see this on the next minor version of the RFC :)



>
> 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
>
>
Cheers.

Reply via email to