Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91261 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98905 invoked from network); 17 Feb 2016 23:13:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2016 23:13:30 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.48 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.220.48 mail-pa0-f48.google.com Received: from [209.85.220.48] ([209.85.220.48:33227] helo=mail-pa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/40-27172-89EF4C65 for ; Wed, 17 Feb 2016 18:13:28 -0500 Received: by mail-pa0-f48.google.com with SMTP id fl4so19142696pad.0 for ; Wed, 17 Feb 2016 15:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=605ZG/wWewuolYR9/q3xggzgN9K964RymCL2oSwiGxo=; b=VNLAuOu9fF7OcbUdvJNjZJdk4L2vRZ0uSsBGxdqka6d+ERLBxTekdJgno/ETLZGggo /m7GOVTOXpox9oNrGzpMZE8bueztKhccMNQvG9x1aLfRAFh+V5LnP+0Rie9SjDfjXVax Z18ERRTM4rJ9FSKEAdFt3AAQDHbFhE4XYn9Stt6ZC04+ylDUasgqlGGx3NBX2vZdMG/V ObAZx5PrgumovRUuyr3PeVlLbMEESsrpmFvNN8Nb94tpfrNRgWznl+ndPabAwOjXgLN2 HCyIJMFmaH+WE6Gyedhb0wOSBaQ/XVfOsLWmak7RoD3lKDBtPfWYP5F3JsuldH5Tvlr5 Je0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=605ZG/wWewuolYR9/q3xggzgN9K964RymCL2oSwiGxo=; b=RTkKeRvZkvKXfuM14GZxD/9D30WmHLTdEzg7v3Qi6FwI6m3h66M8IJJqvMAbKI8SZ3 pHfBv2G7Gpqt1JTE//iZfx0XNtOvI34AUMaQ4H+D7qx9BVNPvwTT1AZSXQ21la07h79O Vi9atct7TOE8Qy9kd4Y12brcO02V6X1VrI0JIIloOzxXcNwJ5RVDgC+8zfBB3U0xCc/U lxNXhxFpfZiWbX8wu/MllJ0fHg+mB8MdnUPyfrNscQHU1VaSnW+aTMPep/7UUAY4wBFG biv8zHfLjF08dmY6P36ROcBxNqYu6X0PMuGc8ptDCDQ0SXlo1GTzXrKz40J/d1hTo7pt F/kA== X-Gm-Message-State: AG10YOSHLVNJuq/YNqSVQNfDMOYojrceSPGJZDo3uqQ2r53hOcEl4GSRpPYhe777U2++GEOivOUK+fUvq81Uag== MIME-Version: 1.0 X-Received: by 10.66.220.7 with SMTP id ps7mr5902651pac.58.1455750804949; Wed, 17 Feb 2016 15:13:24 -0800 (PST) Sender: morrison.levi@gmail.com Received: by 10.66.163.232 with HTTP; Wed, 17 Feb 2016 15:13:24 -0800 (PST) In-Reply-To: References: Date: Wed, 17 Feb 2016 16:13:24 -0700 X-Google-Sender-Auth: 9d2zw32hdxzFsPuN_kENfrthPi0 Message-ID: To: Kevin Gessner Cc: internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Traits with interfaces From: levim@php.net (Levi Morrison) On Wed, Feb 17, 2016 at 12:48 PM, Kevin Gessner wrote: > On Wed, Feb 17, 2016 at 10:26 AM, Levi Morrison wrote: >> >> I want to add my personal experience with traits: every time I create >> a trait it is to implement an interface. Here is a publicly available >> [example with >> OuterIterator](https://github.com/morrisonlevi/Ardent/blob/master/src/Co= llection/OuterIteratorTrait.php): >> >> [snip] >> >> I can see how it would be nice to allow the trait to officially >> declare that it implements some interface (in this case Iterator or >> OuterIterator) which would require that the trait has fully >> implemented the required methods (or declared them as abstract). This >> would be a small improvement but helpful. >> >> I am less certain about the classes which `use` it automatically >> inheriting the interfaces. To clarify: I am neither in favor or >> against that part. Or at least at this stage, anyway. > > > I don't think there is enough benefit from allowing traits to declare > interfaces, but not propagating the interface out to classes that insert = the > trait. It does provide an extra bit of enforcement on the trait's method= s, > but the real value is in making that contract a part of the classes. I do agree that there is only a little benefit but I disagree that it is "not enough". It's a quality of life change to an existing feature that has no impact outside of that feature =E2=80=93 sounds perfect to me. > In what situation would a class that inserts OuterIterator not want to > declare the Iterator class? If every class that inserts the trait would > also declare Iterator, it's needless repetition to require that both the > class and the interface. Funny you should ask, because OuterIteratorTrait implementing OuterIterator is actually a case where not all using classes will want to be OuterIterators formally (just get the horizontal code reuse). This is because I don't want to "leak" the inner iterator because it is suppose to be abstracted. In these cases I use the syntax for using a trait method under a different visibility.