Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74873 invoked from network); 18 Feb 2016 19:16:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2016 19:16:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=chasepeeler@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=chasepeeler@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.175 as permitted sender) X-PHP-List-Original-Sender: chasepeeler@gmail.com X-Host-Fingerprint: 209.85.214.175 mail-ob0-f175.google.com Received: from [209.85.214.175] ([209.85.214.175:33046] helo=mail-ob0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/22-62769-78816C65 for ; Thu, 18 Feb 2016 14:16:24 -0500 Received: by mail-ob0-f175.google.com with SMTP id jq7so82122026obb.0 for ; Thu, 18 Feb 2016 11:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-type; bh=hU3u2zCeYoX1EXxFJaLQg8xvvkB2WwVoVeb+wqx90K0=; b=bLX/WMtTu7kfckcErHo7fekZHtbsqXIKlXhGGnwM7LpJnsF7QWZW7U1xHGSEBYBUb5 +hghnbpQb5XDmqYygZ9ox7buaWMp06VKMtQIt99C+vIO3dZ3vn8CEYdscUtET38Iqxbn FrtltQuGrnIA7KYiOH/Uqn5mHmdnXcxIQo6c6pBXFR5dWDIOcHLsEWp7L1NercXUFGiv ESqHhcW5auIgRuOe/2aALdDP3FyOOwCD6QUgYeZFZVgrFjjKz24BPdH7fCui4hjkA7Tm g0RoI+vWp5I1G7U3EEivUqppxnoD3jN8QrAXCw5L6tifGyhkQbbi+Hd2NWuQReW1ZwFT 7EcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-type; bh=hU3u2zCeYoX1EXxFJaLQg8xvvkB2WwVoVeb+wqx90K0=; b=kAwsCWjzGUCgpdl5rd50J5nTbhN0NYI1lmE5/VBvAzHYDprwdjlqH9ynHhTog8510D +kSKzlkEq8Fw0Z93rnMjjSEcLsuZNUvOQUta18QVSEmtHg4clYxrQGh9vABm30ZvXLJ1 SNdbOtWH+D8aajJtqKIslQiOg+BsCBLlJb5FlmPy9HYfrmkgP9DSrRjZRxOwfKe9gj8w nLjXVEQRlHJlbKU0IbZeGk+dloC0/+D0ZD8FETqaOkbXRuaVmko0oVwQV1+j/12EOXqr 1INHajVwLSA0NQzl4rlHlDHdNT8GpMX9Dov4EpRqrTi6+pGM03eAcJTNaSVK91LYiZaA Jpxg== X-Gm-Message-State: AG10YOQg2xuB/7t61wA8h4nmQWJIJTRo92hsy8aBJkRr409muUz6S8l+35yZRnNcR+yeGl2l5A3K2VPxeFKygA== X-Received: by 10.60.117.137 with SMTP id ke9mr8159116oeb.16.1455822979424; Thu, 18 Feb 2016 11:16:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 18 Feb 2016 19:16:09 +0000 Message-ID: To: Nikita Popov , Kevin Gessner Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7b4720288b6c6b052c10338b Subject: Re: [PHP-DEV] [RFC] Traits with interfaces From: chasepeeler@gmail.com (Chase Peeler) --047d7b4720288b6c6b052c10338b Content-Type: text/plain; charset=UTF-8 On Thu, Feb 18, 2016 at 1:29 PM Nikita Popov wrote: > On Wed, Feb 17, 2016 at 3:25 PM, Kevin Gessner wrote: > > > Hello internals team! I'd like to propose an RFC to allow traits to > > implement interfaces. > > > > I've noticed s pattern in Etsy's code and elsewhere, where a trait > provides > > a common implementation of an interface. Classes that use the trait are > > required to also explicitly declare the interface to benefit. I propose > > that traits be permitted to declare and implement interfaces. Classes > that > > use such a trait would then implement the interface, as though it were > > declared on the class, without declaring the interface explicitly. > > > > I believe this small change would be a useful improvement to the OO > > system. I've written a draft RFC, but I don't have karma to create the > > wiki page for it. Could someone please grant wiki karma to my account, > > kevingessner? > > > > I don't yet have an implementation, but I'll be starting on one once I've > > posted the RFC. I look forward to your thoughts and feedback. > > > > Without given an opinion on the RFC itself, this might be interesting for > context: > > http://hhvm.com/blog/9581/trait-and-interface-requirements-in-hack > > HHVM already supports "trait Foo implements Iface" with the semantics that > the interface is also implemented by the using class. > > Additionally HHVM supports a notion of "require implements Iface" which > means that the using class must implement this interface. > > Why should it matter if the class using the trait actually implements the interface? If the person just wants the functionality, but, for whatever reason, doesn't want to actually implement the interface, why should it matter? I think the trait should HELP the person implementing an interface. The trait should be able to say (whether via comments or an engine enforceable construct) "Hey, I've done everything needed for you to implement this interface" but, at no time, should the trait force the class utilizing it to interact (via extend or implement or use) a 3rd artifact. trait foo implements myinterface {} class bar { use foo;} class baz implements myinterface { use foo;} Both of the above should be legal, and $myBar instanceof myinterface should return false; Traits also already have the ability to force the using class to define certain functionality by declaring methods abstract - however, the trait doesn't care if it is implementing that method via inheritance, because some other interface requires it be implement, or via another trait. > Nikita > -- -- Chase chasepeeler@gmail.com --047d7b4720288b6c6b052c10338b--