Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92471 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87365 invoked from network); 19 Apr 2016 15:34:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 15:34:56 -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.51 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:38699] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/87-43496-E1056175 for ; Tue, 19 Apr 2016 11:34:54 -0400 Received: by mail-wm0-f51.google.com with SMTP id u206so36313357wme.1 for ; Tue, 19 Apr 2016 08:34:54 -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=FFRjTOFkXt4cWImgSnw1Vy8JIav9xtw6DTSKsS6v5gw=; b=YE2ZTuiTTLD50QInKYae9afxGD1t5rYedK8n5dQ2gbrx7RCUUHDvAcJX0WhqGZo+cD XjvEXAQCZr8u6U4ork1EcBJl/txO2xbegK0q9ewulNESN8PwHD/B25XLKv908RF8xnkH 148y5Dv+09TeUEqxZU0OhxtCAzlna6aSnRs/h7Z+ufFyhla1q5MivXz0C8ouNM1HwJyg EwQCbhIjHtnNXCwVDRcPl1KIHqL5ysXkClKKYaM1kmLzbmxEwG5cVdQUCtALFY09Obid EvJzqPJi8INYni8Ys4vWNpHbemwB5VRvFTg5HwUwU4VIRLmkWo6IRl/LT8rHLuL5r2M8 EmFw== 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=FFRjTOFkXt4cWImgSnw1Vy8JIav9xtw6DTSKsS6v5gw=; b=TgAWFgB4dTpMyJdsOkgS+5sk6JAxZiUvcdOfehzowJOntWqM2L8MYaDE53kjgkwEPS MSw5ixU6BLTzvST5l5OFJ5+XWPFuHMewn2ZO0KTZ8moydq3+FohjoMGsNkp0dI54AW3I iLUbjfzWlUTrFrvmniLvtHt3xJdS2M+tQ0A7vmDKdQ8MB4TdrUyYbxL07Ashs3YxcPML 2+/hviLJgbXAYhochaJsAGMN2gpjZ1AwlxZOGAXt7PWqmj/fOnDSiL2InW++2rHgWNw8 KpHqdYuF9BR1JDHYBRIoYzTlnRZwuM2bBf+/sT3q+P0VPTTmGN6Yjd9SyPRQqe8sXis1 sCBg== X-Gm-Message-State: AOPr4FUTrNCiiMl8/jlCzifIRn+1VFCot31ckwfztVFI0fnelw+MvKya7djS9RAZG70Dxw== X-Received: by 10.28.0.69 with SMTP id 66mr24407786wma.61.1461080091471; Tue, 19 Apr 2016 08:34:51 -0700 (PDT) Received: from [192.168.0.77] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id gk4sm859911wjd.7.2016.04.19.08.34.50 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Apr 2016 08:34:50 -0700 (PDT) To: internals@lists.php.net 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> Message-ID: <57164FBE.4070206@gmail.com> Date: Tue, 19 Apr 2016 16:33:18 +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: <57164CE8.4090307@garfieldtech.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) Larry Garfield wrote on 19/04/2016 16:21: > 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 I'm not sure which approach you mean, but in Joe's proposal, you always call $handler as though it was an object implementing the interface; have a look at the ILog example in the RFC. With a typed callable, you can always invoke as $handler(...) will work, but the implementer can't create an object that meets more than one contract, because they can only provide one __invoke method. interface UserEventCallbackInterface { public function handleUserEvent(UserEvent $event): boolean; } interface CommentEventCallbackInterface { public function handleCommentEvent(CommentEvent $event): boolean; } class Logger implements UserEventCallbackInterface, CommentEventCallbackInterface { ... } $logger = new Logger; $simple_user_handler = function(UserEvent $event) implements UserEventCallbackInterface: boolean { ... } In Joe's proposal, $logger and $simple_user_handler can be used interchangeably by calling $handler->handleUserEvent(...); the receiving code doesn't need to do anything special to accept the closure form, because the engine transforms it into the required object. Regards, -- Rowan Collins [IMSoP]