Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92468 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81256 invoked from network); 19 Apr 2016 15:04:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 15:04:11 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:37774] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/56-43496-9E846175 for ; Tue, 19 Apr 2016 11:04:10 -0400 Received: by mail-wm0-f46.google.com with SMTP id n3so34860824wmn.0 for ; Tue, 19 Apr 2016 08:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=CVKPREt6X9nW/aHvPJGwxTH5aD/16JkqNfZdN7a5hhU=; b=S9zFA8pQcrTmiwUarzba/VN3v2j1GA4xMA7RcxKAHdhjJ9Xz6iwvZ6whw82TyUMXZ8 qKbFRfnu02XjJliXggreUcUqFO113c5UreYJqJjLZDxiAsH68Eqrh+g7ijXa/PQxarwW WmLDNaA6FZN5nMnFL4H8RiG80aoio2flCIId012Q+1bUtc6yxktiC7zc33YIgGggmVo+ J+elMz53xPUKo4uNCeMzxcgWe0mc9HZSMyoGvXybbAKnAxtAOuTEcBGBJ73fMDf3kMdl BqsKo/sJ3B9EdEoBVGKYnf3pPUfkVdpVNrjis2ZIgRACH3uxnxY+STLxxcyeAHRp508g uEhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=CVKPREt6X9nW/aHvPJGwxTH5aD/16JkqNfZdN7a5hhU=; b=TNfZZ4fmF5g9XtCqCECY+tYUZA2XecS7sU0ToI7ntuEvR3PvbOBGqlhp3P1wHazg2G 1VqixVlgGGaTQ6LoPrlapHqFv3ghXzBYTlx4J38DCZeYyuOnXmoTJAw/2flfu0cbYnTV 4TvlYyuDoKcXzZrpefs3M8PDc4IpA/VM4pb1b1dRZo0TRGXKMioP7X+vhslEc29v+BIT zzTLB0fd+QNBlDMOx6BC66eIBNm3Q2XZWYXtK5tvnCPIqcNEnOq/DvDgXk3iKphaWdAZ R8ENJeCAwB66KJXn6Qq37WLovfe/ahKl+DGrXM1SUuLMWjGjIZNGnZhNDuCWsKYekC19 miVQ== X-Gm-Message-State: AOPr4FWBnh7rOmzvobp2XgI0xd6Vqh1b+M9SUTKRIhBk20EfowAhmk7BEfiGqFeirgSDWg== X-Received: by 10.28.88.212 with SMTP id m203mr4458788wmb.52.1461078246710; Tue, 19 Apr 2016 08:04:06 -0700 (PDT) Received: from [192.168.0.77] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id w3sm740483wjt.0.2016.04.19.08.04.05 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Apr 2016 08:04:05 -0700 (PDT) To: internals@lists.php.net References: <5716310B.4060104@zend.com> <57163CB0.70608@zend.com> <5716410C.1080904@gmail.com> <57164550.7070008@zend.com> Message-ID: <57164889.1080609@gmail.com> Date: Tue, 19 Apr 2016 16:02:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <57164550.7070008@zend.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Functional Interfaces From: rowan.collins@gmail.com (Rowan Collins) 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. Regards, -- Rowan Collins [IMSoP]