Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:120737
Return-Path: <michal.brzuchalski@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 24647 invoked from network); 3 Jul 2023 12:45:31 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 3 Jul 2023 12:45:31 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id C453F180511
	for <internals@lists.php.net>; Mon,  3 Jul 2023 05:45:30 -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_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: <michal.brzuchalski@gmail.com>
Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174])
	(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 <internals@lists.php.net>; Mon,  3 Jul 2023 05:45:30 -0700 (PDT)
Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-bd6446528dcso5109495276.2
        for <internals@lists.php.net>; Mon, 03 Jul 2023 05:45:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20221208; t=1688388329; x=1690980329;
        h=cc:to:subject:message-id:date:from:in-reply-to:references
         :mime-version:from:to:cc:subject:date:message-id:reply-to;
        bh=js+pfmf9lX0JvXgDAcOPI8jpOBEiDCw9kZwds4qNuXQ=;
        b=oFCJHuyOLiRNli8EgLaW/4MfgQILnbbFg1iRYKpbh0smT8Qo9T4Zz8SP/GwdjLu1Nm
         Qig/9DdCL+LrxX3i2+EV5PaVln+dHs61LcmEAVvmVZ9/L51bJfAN1QhiH+YlEcT7SUDr
         nX96evql2Eum0rf4fQocrCPYRDbZOj1PM1LZTXN3EDnE8MrWt3yAebpjNkojtyVN9/hr
         KNKiXVsCCZH0TlAQ9phtj2t6aoWJbKTzT1mNGQNjDhRZ5CfHCHqTsF81nMcCn/k3paLe
         3IZL9EEg0+rW+pAUfMwPBXviyW9RkMX+hWaXCJpUAKCyuiI7HiclFtutursCc+pjVyx+
         a0ug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1688388329; x=1690980329;
        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=js+pfmf9lX0JvXgDAcOPI8jpOBEiDCw9kZwds4qNuXQ=;
        b=bYma/oeGGHMsrOzvlD9TFibTPKBKSSvnR9m3KZZ36Vx2OcOyp3mAuUgiYp7fb0ZQwi
         Q3SdS0MeZ/+WOYBbmTvrX2OwV4uid+g2d1eu66OJ4Fz1ENt8WOYZxfhLU+XTfx5Jshn5
         oXHOMVvFE8G040qGykPYRv3C9LpCjvAclrFrtJS4LeCPncH589BtPl7PGHNgrcLVA/Z1
         t7XS7RdF4NyNeM2PD7XbpqyZGB1Rl3XFRMuJflwFKG3YmOV5vVMtPplD69aiahpwlhvY
         GFJXoXQvkzpyfVLD3GZXBYgTm6AqK1uvjtwmuTlt1g0RuAi5sxOGhqcuYuT1lWVCl7Vw
         XWTg==
X-Gm-Message-State: ABy/qLY1urUbklQlW/Wm/9PE6W9XDoiqTfcOkJl74YVMN9iyWlnDwcHJ
	w5848n0hWIcpWtDeAtwxfG5y9NabGK5rd1gQfVGh807AkEfA4A==
X-Google-Smtp-Source: APBJJlFV6I2Z97uM5mib7Mlpz7iieIdgk7guXf6zEihguI6SdciAxD/S5o1unIPmtks5tkE6sqwoK+tS/r5hW+2wQgA=
X-Received: by 2002:a25:9c86:0:b0:c1c:7458:87f2 with SMTP id
 y6-20020a259c86000000b00c1c745887f2mr9046714ybo.26.1688388329498; Mon, 03 Jul
 2023 05:45:29 -0700 (PDT)
MIME-Version: 1.0
References: <CAFMT4Nq3y+XKUP7aG7F7aht1DdM7dpqxMT-hcS+Nyvc9FaT=+A@mail.gmail.com>
 <CABdc3WoWSEP0Nu_KEyzSbBAkyZkY+m+bJroBBpJge9SbB4VPNQ@mail.gmail.com> <3a3e7781-c2b4-2880-8048-d19458ac287d@heigl.org>
In-Reply-To: <3a3e7781-c2b4-2880-8048-d19458ac287d@heigl.org>
Date: Mon, 3 Jul 2023 14:45:18 +0200
Message-ID: <CABdc3WqzfrXFG9W61oEVbCC7jaOABabgkcKUM5Q6pAJfJAjJ3g@mail.gmail.com>
To: Andreas Heigl <andreas@heigl.org>
Cc: internals@lists.php.net
Content-Type: multipart/alternative; boundary="0000000000009f6e0205ff948a35"
Subject: Re: [PHP-DEV] [VOTE] Interface Default Methods
From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=)

--0000000000009f6e0205ff948a35
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

pon., 3 lip 2023 o 14:26 Andreas Heigl <andreas@heigl.org> napisa=C5=82(a):

> Hey Micha=C5=82
>
> On 03.07.23 13:32, Micha=C5=82 Marcin Brzuchalski wrote:
> > Hi Levi,
> >
> > pon., 3 lip 2023 o 02:11 Levi Morrison <morrison.levi@gmail.com>
> napisa=C5=82(a):
> >
> >> Chatter on the [Interface Default Methods RFC][1] has been quiet for
> >> the past 6 days, and the feature freeze deadline is fast approaching
> >> for PHP 8.3, so I'm moving this to vote. It'll be open for two weeks
> >> as usual.
> >>
> >> Thanks to everyone who discussed weaknesses in the RFC during the
> >> discussion phase.
> >>
> >>    [1]: https://wiki.php.net/rfc/interface-default-methods
> >
> >
> > I voted "yes", my personal use case waits for this feature. My use
> > case example:
> >
> > https://gist.github.com/brzuchal/89e9481bbd34a6ce3d95a68eabff038b
>
> I've added two already possible solutions to that as comments.
> >
> > With interface default methods I'd no longer need traits that implement=
 a
> > single or in rare cases 2 methods that
> > use their respective methods returning objects and iterate in Generator
> > fashion over a paginated result set.
> > This is not an issue if there is one implementation of the interface bu=
t
> > when I decorate to apply some:
> > * caching
> > * logging
> > * failover
>
> That requires that you are in control over both the interface AND the
> implementation. In which case you probably do not need an interface and
> the Trait would be enough (using `abstract public function` in traits
> works after all)
>
> So you could even skip the implements part.
>
> As the interface should be designed specifically to be
> implementation-agnostic, adding implementation to the interface is
> counter-productive.
>
> Adding abstract methods to a trait and then just adding the traits is no
> issue at all especially when you are in control of the interface AND the
> implementation.
>
> When you are NOT in control of the interface... well, you can't expect
> to have a default implementation and I am already looking forward to the
> complaints that it is great to have a default implementation, but not
> *that* one.
>
> There is a reason why the respective construct in Rust (which was
> mentioned in the RFC) is called a Trait and not an Interface.
>
> So to decouple the contract from the implementation it is necessary that
> no implementation is part of the contract.
>
> >
> > then the trait has to be attached to every class besides that it has to
> > exist which is an additional symbol here.
>
> Stop using `implements` at all and solely rely on `use`.
>

I use an interface for mocks in unit tests.
A default interface method allows me to remove some traits which are not my
favorite and I'd like to remove them all.
Turning the interface into an abstract class adds an inheritance that I
want to avoid.
Given that, it true is that it is possible to solve the problem differently
but not without side effects (either lack of contract or inheritance).

Cheers,
Micha=C5=82 Marcin Brzuchalski

--0000000000009f6e0205ff948a35--