Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92470 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85601 invoked from network); 19 Apr 2016 15:31:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 15:31:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=marcio.web2@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marcio.web2@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.53 as permitted sender) X-PHP-List-Original-Sender: marcio.web2@gmail.com X-Host-Fingerprint: 209.85.218.53 mail-oi0-f53.google.com Received: from [209.85.218.53] ([209.85.218.53:34576] helo=mail-oi0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/17-43496-43F46175 for ; Tue, 19 Apr 2016 11:31:01 -0400 Received: by mail-oi0-f53.google.com with SMTP id k142so12452412oib.1 for ; Tue, 19 Apr 2016 08:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QsyS78ze/o45XOhAjeMm+s4JNZvFAx5nFlOyUOKQeBs=; b=kLO4euV1VX5MdGeu6rRQxdcwxcIbg4h3PBqn8cBPT0bJViKThP+Rp16It+lJdcO+/+ rl6pfQ+nX5vXAssDvOA/wIw+yD3Nmlx8uosipMyCvaCHvTGh1h1h3hp+OsrS9jXZXbbf IZ4YeJUZchZsXSdFTFW4aBRTFX04Xd3dgQgw6iNUPaZNsB51J0uDXqnn2/tArP2OI9sp xhfrQjSBlZYvEIPIw1OUNXEeg9z85LpjIFvqogy74JE5VV8vsmbn2Ur5ygHaW9Ookga7 nDqEcOJ4LGCO6t/ivI6bJvfP58AnPfnURfI359piDsBwsCoVWBX9n5uuHRPJkvyMDGVF /4xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QsyS78ze/o45XOhAjeMm+s4JNZvFAx5nFlOyUOKQeBs=; b=Mu8XgLXSF9RosKG5d9Hevnu+6E5iR4WdV4p7EzmNLjZrTzFKNp++M4Ptht/3BEXyru IV8XdarmqAzkiFBJ/zSSF+Gkp7nRlzU8l0J/2G+BlOwGYXAU1GOxgr/MH8UGg9wrDcuA 3ESIR9xrJ5YmdEvrohuWkT19KczYjdSfDO0VQaXii87S+mjd1b9DaxaXwSdc5kJ4SmiK W7n4l6TXY++k8d3KtlRocUByNAKK78KH88GHcaVLU1OhRnMs5mPOJu+oYxfZVLdgDlA+ 1gRvAjQUlXNa/u1dCpPQd+jJWJYA0qoCawzRQiRJ+9MYSL1sHl4sbL0FtwOXzKPOB55/ 5eAw== X-Gm-Message-State: AOPr4FWycRYdU8394ujZkvz181Fv79e/wdxrToADFETtrploNtnS2G5VR1+Ls21AKldEDkZbEKZ/rtxWn89ySA== X-Received: by 10.202.193.10 with SMTP id r10mr1318155oif.110.1461079858309; Tue, 19 Apr 2016 08:30:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.192.198 with HTTP; Tue, 19 Apr 2016 08:30:38 -0700 (PDT) In-Reply-To: <57164CE8.4090307@garfieldtech.com> References: <5716310B.4060104@zend.com> <57163CB0.70608@zend.com> <5716410C.1080904@gmail.com> <57164550.7070008@zend.com> <57164889.1080609@gmail.com> <57164CE8.4090307@garfieldtech.com> Date: Tue, 19 Apr 2016 11:30:38 -0400 Message-ID: To: Larry Garfield Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113dc36ef16fa20530d82916 Subject: Re: [PHP-DEV] RFC: Functional Interfaces From: marcio.web2@gmail.com (Marcio Almada) --001a113dc36ef16fa20530d82916 Content-Type: text/plain; charset=UTF-8 Hi! 2016-04-19 11:21 GMT-04:00 Larry Garfield : > On 4/19/16 10:02 AM, Rowan Collins wrote: > >> Dmitry Stogov wrote on 19/04/2016 15:48: >> >>> callable-type is much simpler solution for this use-case. >>> Usage of Interfaces to check function prototypes is a bit tricky, but >>> yes, this is a possible use-case. >>> Do you like to work with framework, that use this trick for every >>> callback? >>> >> >> If you don't use __invoke as the function name, you can have a single >> class implement multiple contracts, e.g. to register for more than one >> event type with different signatures. >> >> I guess if you had callable-types *and* union types, you could get the >> best of both worlds: >> >> interface UserEventCallbackInterface { >> public function handleUserEvent(UserEvent $event): boolean; >> } >> public function registerCallback(EventCallbackInterface|callable(Event): >> boolean $handler) { ... } >> >> The implementation has to be a bit fiddlier here, because you need to >> sometimes call $handler->handleUserEvent($event) and sometimes >> $handler($event); with a functional interface, the engine makes >> $handler->handleUserEvent($event) work for you. The cost is that the call >> site has to be a bit more verbose to specify the interface, rather than >> implicitly meeting the contract. >> >> I believe Joe has both $handler->handleUserEvent($event) and $handler($event) cases covered already. This means that $handler->handleUserEvent($event), $handler() and $handler->__invoke($event) should be 100% equivalent. > Regards, >> > > Which is why I'm not sure I like that approach, because the place I then > call $handler needs to have a conditional in it. There's another RFC that > was posted to Twitter but hasn't made it to the list yet that seems to > solve this better: > > https://wiki.php.net/rfc/callable-types > > (My apologies to the authors if they aren't done with it; it's on the wiki > so I'm assuming it's safe to mention in public.) > > Yes, it it's ok to mention the RFC. We are going to move it to discussion phase ASAP some minor issues get a fix :) > That allows just the callable-type syntax (which I presume is what you're > referencing), but you can then pass an object in using []-callable syntax: > [$handler. 'handleUserEvent'], and then registerCallback() doesn't care if > it was a function, method, closure, or whatever else. It can just () it. > > -- > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --001a113dc36ef16fa20530d82916--