Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120633 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30778 invoked from network); 20 Jun 2023 04:30:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Jun 2023 04:30:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AC163180506 for ; Mon, 19 Jun 2023 21:30:33 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) (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 21:30:33 -0700 (PDT) Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-440c5960b58so22060137.3 for ; Mon, 19 Jun 2023 21:30:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687235432; x=1689827432; h=content-transfer-encoding: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=khLf31dgIG39uBYm4O+iT/n8Cj91SfW3T8//lXqNQE8=; b=DNr3/Ae46MxBl7vNvnykFy0QVBrxczAJBd20HKHx2s8/tkblZMguUx5wW56U4BpiE3 Ao6+xBePK8t8Gy3rhGkRZOaH2FqiXpkFuhSFg2gV0o1wMAieHiUEzu+RpQJ0Q+IDmu2o CNv6gk0WqD8u/DN5Yjzcgu0s/G2at+diBi8K8YkvvmM5G0gWESr8jpwCcGspLiYIi8Iy kBDZ71mHZAAxAKYknUt78vmgCLd+jeNX4yIrdkg6yZMPFvz7remnSMobBrJnzgitVW3A 97t3dMiqsZbZyMHPtqrbaCTBJsjrK7oZhOpmtgUqUtyAaYHDl7b61hssVIjtG6j2P1nj SwMw== X-Gm-Message-State: AC+VfDyKJjjohmVVegMPj/TnPPKZBqbTrjlzEUxVs7QmG5WUXTnMEede xtCTBqCiaiwS5ni0RP+Ij2+ABCJrt+Ir6rrTxk8= X-Google-Smtp-Source: ACHHUZ7oPXbEw5Xhc+8ixVE1rZAR2R+w5nRvBUfyEoyxJIFkPMCOp9udRMfQScmkL0NSbDQwOx4R+dgProP5jjL1CyQ= X-Received: by 2002:a67:f58f:0:b0:440:ab5b:a549 with SMTP id i15-20020a67f58f000000b00440ab5ba549mr2249278vso.18.1687235432313; Mon, 19 Jun 2023 21:30:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 19 Jun 2023 22:30:15 -0600 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: Levi Morrison , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Interface Default Methods From: levim@php.net (Levi Morrison) On Sat, Jun 17, 2023 at 6:05=E2=80=AFAM Alexandru P=C4=83tr=C4=83nescu wrote: > > Thank you for this! > I like the proposal and I think it fits well. > I'm used to it from Java and I don't know any reason for it to be > considered a bad practice since it was introduce, about 9-10 years ago. > > 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? Java > introduced this only in the next version. > The private methods would be invisible to implementing classes and to > anything else, of course. > We can also add them at a later point but it might be better to have the > feature complete now. > > Sidenote: I don't think protected method should ever exist on interfaces; > that should remain for abstract classes use case. 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. > 2. The only use case for myself for ever using traits would be if traits > would offer a default implementation for an interface. Now with a default > implementation offered by interface itself, sounds even better. > However, I can see how there could be more than one provided default > implementation that can be offered. > 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 interface? 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.