Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120634 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34260 invoked from network); 20 Jun 2023 05:22:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Jun 2023 05:22:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7959C180538 for ; Mon, 19 Jun 2023 22:22:09 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 19 Jun 2023 22:22:08 -0700 (PDT) Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-544c0d768b9so3525870a12.0 for ; Mon, 19 Jun 2023 22:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687238528; x=1689830528; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bNOx0YSBD35Ev8+X7UOMsTy3oBA6vbD3d1km3qKMS8A=; b=DzPLJu36NV/keZtf4s/AZ9Bq+LKH0O8ZMkXMR4D7KwTDAsdC8muNvBAq/EhIcSPdr1 mBC8JxuZeG0Y+rUgF3SgYOJ1BTSnDRXnyBV2Xhq0epEN/I5OOKMoXiu8acuv1L54sNA1 zPnohEBMYDssoIj3wx7d3KeVBv2npEdSBpQv/LWUqDmzvnPTUf9d0QAN9fUcRewpZsWm qWPPB46WZY9cB0eHx4Pl4dIGBf91nCg6NbEMgS0myCxKtJCa0My+7gzlhWC7jG4wrz/a e0MB4w7grk1JaRQJuGoPm/j7KP9/7ez3xi6xJDqMX0fQWeNILW9Upuc7VICBdOt1TGgt Nknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687238528; x=1689830528; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bNOx0YSBD35Ev8+X7UOMsTy3oBA6vbD3d1km3qKMS8A=; b=VEj3lF6OF8VAfxyMjqQJG/ME7jrgZOSNnjjg5KCsz/qKM1ZLPW6+B1wjKfYhO6tO+V qj6xq9wSRf0bhDweiNkZuZU7oiICMCEACS+hvQa/VVFijRUbJ6QlwUJ8ihGxJeW3DHZq NbEz25915b46s11VWbNQ8UfydPbbH4xg9GO7SlrRhO0PB2nFhQL+1pQNxQEUOXFhuaFO SvkZFQIZGsw/ZoF9SbNgQGUPaAustVSq6rkx8Panv23vTXOHGv2Cbr675owJI8UyJ/Ox wZ5uE07KBgrOINd4EvzSF4merT9yJNCOz8rJU2DepJawq+6vpEyF89AaFQ59P81Vixh/ QxFQ== X-Gm-Message-State: AC+VfDw7aUkPa36GCkw83vbzm1DGiMu/DrTc+b+j+yQoKzDga44YkAex HgJE7FgtdII8QsdZLeEmflFB0vCK8Oa+3Dp7tq1+5lp67QE= X-Google-Smtp-Source: ACHHUZ7o0W84Ua3qkwN24lJcxi3mOU/5IRghbTJKY3rKDZ749GC3byicnejv1YIwVFXauoLvOpflHryBJs4Ol/8h1hU= X-Received: by 2002:a17:902:f7d5:b0:1b3:a41e:8dc5 with SMTP id h21-20020a170902f7d500b001b3a41e8dc5mr10223049plw.49.1687238527568; Mon, 19 Jun 2023 22:22:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 20 Jun 2023 08:21:50 +0300 Message-ID: To: Levi Morrison Cc: Levi Morrison , PHP internals Content-Type: multipart/alternative; boundary="0000000000001652cc05fe88d5dc" Subject: Re: [PHP-DEV] [RFC] Interface Default Methods From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000001652cc05fe88d5dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 20, 2023 at 7:30=E2=80=AFAM Levi Morrison wrote= : > On Sat, Jun 17, 2023 at 6:05=E2=80=AFAM Alexandru P=C4=83tr=C4=83nescu > wrote: > > > > 1. Do we want to allow also private methods in the interface so that it > > allows code reuse or better code organization in smaller methods? > > Sorry for the delay in responding to your message. I have implemented > support for private methods for people to experiment with. As far as I > can tell, it works as expected and I don't see any issues with them. > Of course, they only make sense as helper methods to the public > default methods. > > I'd like to hear what others think about allowing private interface > methods that have method bodies, but I think it's easy and sensible. > Looks good to me. Thank you! > > > Would a method implemented by a trait have higher precedence over the > > interface default implementation? > > Would a trait offered implementation be directly usable by the interfac= e? > > I'm not entirely sure what you are asking about traits, so I'll try to > clarify. In a class which uses a trait to implement an interface, that > trait method will take priority over the interface's default method. I > will add a test to the PR to make this more obvious. > Yes, that looks good, this was the first question, exactly. Sorry for the lack of clarity in my second question. Is it if it would be allowed to have something like: trait Trait1 { function method1() { echo __METHOD__, "\n"; } } interface Interface1 { use Trait1; function method1(); } So both trait and interface can be used independently without code duplication. A more complex scenario where this might be useful: // external package interface Interface1 { function method1(); } interface Interface2 { function method2(); } // internal package trait Trait1 { function method1() { echo __METHOD__, "\n"; } } trait Trait2 { function method2() { echo __METHOD__, "\n"; } } interface Interface3 extends Interface1, Interface2 { use Trait1; use Trait2; } Where it will allow either usage of a class for: - Interface1 with Trait1 - Interface2 with Trait2 - Interface3 that would already have the method implemented. Hope it's clearer now. I don't know if we want to support use of a trait in the interface but I think the RFC should mention that it is or is not supported. Thank you, Alex --0000000000001652cc05fe88d5dc--