Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92464 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72151 invoked from network); 19 Apr 2016 14:32:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 14:32:15 -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.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wm0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:36367] helo=mail-wm0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/F4-43496-C6146175 for ; Tue, 19 Apr 2016 10:32:13 -0400 Received: by mail-wm0-f48.google.com with SMTP id v188so164770199wme.1 for ; Tue, 19 Apr 2016 07:32:12 -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=/lO23cYxD56DYS9i5gR2+xxKZg6mKl3t0UIMtztFryk=; b=BwNBgYu98lydlNBOcZltggwrE7t/RjPsyn4/nz8SbC5v36LVOj1EuslA2ng1d2/Q21 dDY/zdru1QuPgzGAFOysiw/8V0aBY7EwQ++I5Npf2/AK/GV62mmBzaRWstAjer6VTpep JuKJxxnS7sqx9vaIzi42fgbEYAsiPuYCi2Htd2bxkpyNaygB9aMYd5TF6IhzqRH1tIv9 6D/ylLJEe6r9NdMQlGtIGQ+/8xVwx41VuVsSysFO8oiPVEw5rBmi60r8JvAjt580U5Sp gl47o/9ad7ITDBAjHkaMb4DQL8d4/I5aKc65GOdbh2XzCXbvRklp4c3Rs91rcpqH3kvS 7Dmw== 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=/lO23cYxD56DYS9i5gR2+xxKZg6mKl3t0UIMtztFryk=; b=mfQZY3QUfjKR+KzCiZVXWSzDLiIriMLfLjEohxuXrIaMOeyRhCoALP5gPZ/jajidQ3 xOaPWq9nIuVcVm0HDLZIEeBjOypQdNXu44w+s6DDYCMPTZnH73kfQ2+d376EkVzdBBTi ewp0GlYn9ae77wgv0aRilzzyrTaIkdgi4mHznHF9yPdl5aswb3Xt6wvOw8cAEkz3nh2M vsYtNBYHdCnuI5gsMtRCvk7PSXK6ce+R4Kr1HTtKyS0SUz71OYkkTufPxN/DJCWJZg6Y 2YlJPlP4YgbphfoDoNV8fWciHDyfdzOP6z6piDVyFPUXg1Hx71RGZtfC8qYuEWd5ZxmI FDkw== X-Gm-Message-State: AOPr4FXqlX7UTU58DU640nJCVZB/zpsPT8nuhlR15m/54sAM4x+yoF7dNcfGR4emraOPmw== X-Received: by 10.194.2.225 with SMTP id 1mr4009823wjx.29.1461076329737; Tue, 19 Apr 2016 07:32:09 -0700 (PDT) Received: from [192.168.0.77] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id lh1sm574406wjb.20.2016.04.19.07.32.08 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Apr 2016 07:32:09 -0700 (PDT) To: internals@lists.php.net References: <5716310B.4060104@zend.com> <57163CB0.70608@zend.com> Message-ID: <5716410C.1080904@gmail.com> Date: Tue, 19 Apr 2016 15:30:36 +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: <57163CB0.70608@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:12: > I prefer intuitive concepts, that I may use without rereading manual > again and again. > For this one, I even can't imagine a natural (not over-designed) use > case. The use case that came to my mind is kind of the other way around from "syntax sugar for anonymous classes" - providing a contract for what a callback should look like. In essence, it's an alternative to specifying closure type with a generic-like syntax, as proposed at https://wiki.php.net/rfc/callable-types Say you currently have this: public function registerCallback(callable $callback) { ... } You could instead specify what the callback needs to accept and return: interface EventCallbackInterface { public function __invoke(Event $event): boolean; } public function registerCallback(EventCallbackInterface $callback) { ... } Using __invoke as the method name may or may not be a good idea, but it interestingly means I don't need to change the code that runs the callback, I can just use $callback($some_event); Then if someone wants to use a complex object, they can; and if they just want to use a closure, it has to meet the contract. Regards, -- Rowan Collins [IMSoP]