Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92673 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65720 invoked from network); 24 Apr 2016 03:28:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2016 03:28:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=mathieu@rochette.cc; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mathieu@rochette.cc; sender-id=pass Received-SPF: pass (pb1.pair.com: domain rochette.cc designates 62.210.206.189 as permitted sender) X-PHP-List-Original-Sender: mathieu@rochette.cc X-Host-Fingerprint: 62.210.206.189 texthtml.net Received: from [62.210.206.189] ([62.210.206.189:36797] helo=texthtml.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/C8-07837-F3D3C175 for ; Sat, 23 Apr 2016 23:28:00 -0400 Received: by texthtml.net (Postfix, from userid 65534) id 4ED6279F; Sun, 24 Apr 2016 03:27:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on b7ba30992c3e X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,HTML_MESSAGE autolearn=ham autolearn_force=no version=3.4.1 Received: from [192.168.1.70] (stunnel_mail_1.mail_default [172.27.0.8]) (Authenticated sender: mathieu@texthtml.net) by texthtml.net (Postfix) with ESMTPA id 7EEE776B for ; Sun, 24 Apr 2016 03:27:40 +0000 (UTC) To: PHP internals References: Message-ID: Date: Sun, 24 Apr 2016 05:27:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Thunderbird/47.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------0248C1BC8F9A23053B3F0A1B" Subject: Re: [PHP-DEV][RFC] Callable Types From: mathieu@rochette.cc (Mathieu Rochette) --------------0248C1BC8F9A23053B3F0A1B Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 04/23/2016 08:34 PM, Marcio Almada wrote: > hi! > > From: Mathieu Rochette >> 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? I wouldn't say it's indispensable. it's just that in the previous example, the class Foo cannot say that the #rd argument of the callable is either a Logger or null. that means that giving function(int $done, int $remaining){var_dump($remaining);} works but function(int $done, int $remaining, Logger $logger){$logger->debug($remaining);} does not even though it is compatible with the callable signature. and afaikt, I cannot make a signature without a default null value or one of the rfc about union types or nullable types > > >> and last one, will instanceof supports this new syntax? >> >> > Yes, please expect to see this on the next minor version of the RFC :) great ! I've seen someone mentioning variadics so I made a few small tests, I think those two should work (they currently don't): https://3v4l.org/eZgR9/rfc#rfc-callable_typehint https://3v4l.org/N7i0u/rfc#rfc-callable_typehint and this one should not: https://3v4l.org/fcRlT/rfc#rfc-callable_typehint > > > >> 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. > -- Mathieu Rochette --------------0248C1BC8F9A23053B3F0A1B--