Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125520 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 17FFB1A00BD for ; Thu, 12 Sep 2024 08:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726131671; bh=LTeGi8WGhl9JPiqVuAHfNhiDIMdqzBaiVA5W6w4pYrs=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=ZzGDUkUpeqrymZ/ObbuOGA5rFO3dEjIhTRQf0l8M+ZtQuXztUXxkunZusN6xsFJhU EWmiBHoS9APtiNPyCp4on3jycvsgde1krEOIBAjTv/RdGvSkEwEdPuABE1aXWqM1ZG ssuKYrZh/6bVMVl5/shmboRYq7nzRZRR1UfeLyDAuND6AyFeTzmcRPL3xmvt+Wwsfz 6hBGe8I7gD4JZIcW2NADkNVETHb0hBsg6tfx+1R18WBlQti6vLBP7bolUQy+0Ubl89 4+tOPmKmpo91HS1IbH9KgsXdc9HfVP7dxCNf2Cb6o2neyUFuEb6Mox/dsRy8U1gp10 U/hd7ah+G/HBg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F753180052 for ; Thu, 12 Sep 2024 09:01:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_KAM_HTML_FONT_INVALID autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 12 Sep 2024 09:01:09 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2054feabfc3so6042925ad.1 for ; Thu, 12 Sep 2024 01:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetbrains.com; s=googleapps; t=1726131546; x=1726736346; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=SLZ0bovYJyaI9apYn+Xw6Ug3yvIgIPnSSQUafINceRQ=; b=fYdD0uBxU0OC6PtKni7xz1xj6guomLyeDGpabaYOgvP5ZnVqrBBQG3CvPft/qeCTpe 61vhQC+jPk24D1221HvQuXgg+8WTUiCXv1HOWBJ3wfDsuiMfY4Rbk5DRDj32RVntH2lL nYpmjT794hraZncNCfErRq45ZNa7X+saA8f2U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726131546; x=1726736346; h=cc: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=SLZ0bovYJyaI9apYn+Xw6Ug3yvIgIPnSSQUafINceRQ=; b=FBML3/yTIj7QMqwU0VQIsS+/z5VgKatI2oLnfXwW+lPUWKw5KWAWk/AssJHaVuXQaX 6BinUodgl0KbpidZJqvBYRfd1hOF+Tca3WhmspQNpVfdNaUNeXoKZJb/xb8dqOHbMquL IjnUf/TK+j6sUekfgvWOKaaNYz5dRoH72rcitA45FeznJjVV50v/Y5NHz+ALFKCbZvT4 PS0ofn0Mv1I9JihjNBMG3ECZ7iq3EW1cwOUwl9FJNw5Wx0WM/vBxFX4z9EvXFnK23yGf J5S3DRtpiCdC9z8SmRoHh9e5PtP3m4kiO2YqJHHPnPPqqy9Rp6XoycJQjWMZ2u4qUqid M8hg== X-Gm-Message-State: AOJu0YwfWnroue7LultgFjidw9hWD29Z3NfVrfuf6m3HsQhwTBcvOa82 uW2IhAk3TIIUTkbh/KxQCtsPTtJQs2XiGWUTikm48KjkGOiAIZbgGrP89SH+ceb6NcOjmLf/12e eOC0ZO8unHfX1wT4htu6Emd1YBZTyVZHnusxUGKN/G3kbkkhKbg== X-Google-Smtp-Source: AGHT+IEQnDuACRAQnoOXCk1FRO2rza8QlNepJX+2GfG2EZ9dC8FsFMv0C3FTX7jRolTMHYKZddYHLISXfVyB2mux3A0= X-Received: by 2002:a17:902:e54e:b0:207:6fd:55d0 with SMTP id d9443c01a7336-2076e31b8bamr29048115ad.8.1726131546351; Thu, 12 Sep 2024 01:59:06 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 12 Sep 2024 10:58:55 +0200 Message-ID: Subject: Re: [PHP-DEV] [Discussion] Implementing interfaces via traits Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000a85a320621e8516b" From: brent.roose@jetbrains.com (Brent Roose) --000000000000a85a320621e8516b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Folks Thanks for the replies. If interface default methods are not entirely off the table, then I agree that's a far better option, for sure! I'll hold off on writing my arguments for them until a thread pops up, I think it makes a lot of sense though. So consider the idea of traits + interfaces on hold until there's clarity about interface default methods. Kind regards Brent On Tue, Sep 10, 2024 at 11:03=E2=80=AFPM Gina P. Banyard wrote: > On Tuesday, 27 August 2024 at 09:25, Brent Roose < > brent.roose@jetbrains.com> wrote: > > > Back to PHP, using traits as types seems impossible, since traits are a > compile-time copy/paste mechanism, which means there=E2=80=99s no type in= formation > available about them at runtime. > > However, allowing traits to implement interfaces would solve this problem= : > these interfaces would be copied over to classes during compile-time, and > the interface=E2=80=99s type information is available at runtime. On top = of that, > traits already have well-defined rules for conflict resolution, so we > wouldn=E2=80=99t need any additional syntax to handle edge cases. > > > Traits are very ill-suited for this because everything from a trait can b= e > overwritten: > > > trait T { > public function foo(string $v): int {} > } > > class C { > use T; > > public function foo(array $v): string {} > } > > > This is valid code, now imagine T implements interface I: > > interface I { > > public foo(string $v): int; > > } > > C cannot implement I, moreover the conflict resolution mechanism just > exposes more problems as you can rename a method from a trait, or change > its visibility. > > > > - > > Even though it was not accepted, the interface default methods RFC > approached the problem from a different angle [4]. > - > > While a majority disagreed that interfaces should implement their own > methods directly, I remember it was a heavily debated topic, and belie= ve > that approaching it from the other side might be easier to accept. > > > One part of the contention came that this feature was proposed in June of > 2023, weeks before feature freeze, and that no attempt at restricting the > implementation of the default implementation was made. > I still think default methods for interfaces make more sense then trying > to fix traits, but also default implementations only really make sense fo= r > interfaces with multiple methods where one is a "core" method that remain= s > abstract and the default implementations rely on it to be implemented. > > > As such I am not really convinced of the utility of adding interface > support for traits considering all the issues I can foresee happenning. > > > Best regards, > > Gina P. Banyard > > > > > > --000000000000a85a320621e8516b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Folks

Thanks for the replies. If int= erface default methods are not entirely off the table, then I agree that= 9;s a far better option, for sure! I'll hold off on writing my argument= s for them until a thread pops up, I think it makes a lot of sense though.<= /div>

So consider the idea of traits=C2=A0+ interfaces o= n hold until there's clarity about interface default methods.

Kind regards
Brent

On Tue, Sep 10, 2024 at 1= 1:03=E2=80=AFPM Gina P. Banyard <internals@gpb.moe> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
On Tuesday, 27 August= 2024 at 09:25, Brent Roose <brent.roose@jetbrains.com> wrote:

Back to PHP, using traits as types seems = impossible, since traits are a compile-time copy/paste mechanism, which mea= ns there=E2=80=99s no type information available about them at runtime.


However, allowing traits to implement interfaces would solve this pro= blem: these interfaces would be copied over to classes during compile-time,= and the interface=E2=80=99s type information is available at runtime. On t= op of that, traits already have well-defined rules for conflict resolution,= so we wouldn=E2=80=99t need any additional syntax to handle edge cases.


Traits are very ill-suited for th= is because everything from a trait can be overwritten:


trait= T {
=C2=A0 =C2=A0 public function foo(string $v): int {}
}

class C {
=C2=A0 =C2=A0 use T;
=C2=A0 =C2=A0
=C2=A0 =C2=A0 public function foo(array $v): string {}
}<= /span>


This i= s valid code, now imagine T implements interface I:

interface I {

=C2=A0=C2=A0 public foo(stri= ng $v): int;

}


C cannot impl= ement I, moreover the conflict resolution mechanism just exposes more problems a= s you can rename a method from a trait, or change its visibility.


=

  • Even though it= was not accepted, the interface default methods RFC approached the problem= from a different angle [4].

  • While a major= ity disagreed that interfaces should implement their own methods directly, = I remember it was a heavily debated topic, and believe that approaching it = from the other side might be easier to accept.

<= /div>

One part of the contention came that this feature = was proposed in June of 2023, weeks before feature freeze, and that no atte= mpt at restricting the implementation of the default implementation was mad= e.
I still think default methods fo= r interfaces make more sense then trying to fix traits, but also default im= plementations only really make sense for interfaces with multiple methods w= here one is a "core" method that remains abstract and the default= implementations rely on it to be implemented.


As such I am not really convinced of the utility= of adding interface support for traits considering all the issues I can fo= resee happenning.


Best regards,

Gina P. Banyar= d




--000000000000a85a320621e8516b--