Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120626 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5555 invoked from network); 19 Jun 2023 21:12:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jun 2023 21:12:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F350418050B for ; Mon, 19 Jun 2023 14:12:28 -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-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 14:12:28 -0700 (PDT) Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5608a4eb782so245025eaf.1 for ; Mon, 19 Jun 2023 14:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687209147; x=1689801147; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=vlbPW/9a64l7E9zKncDfIqo+N9kap6U2HGHfiCdgBDk=; b=HfIdMTi0wyULusxMfRsOtygG9NLxbltHGSiOv0FSVjuvotv9n/CcxIyZvtJPfh6Q6p 1D8HPKObxu1A+42ArngbZ5rrhgMRulgS5nmwJY7+STc9X4QvYuqJogxYR/WaecdCB4cK f4VlkiGobxqwoECKMxzf5cS7ysLQrRb8qKpacD9FMHSC1OWchiFlKRHctEoWxRdfEFQf L7lW+kK90FPiPL+P2VLr+ESj6xh3kVw8i8gPR5JuCD9Axg1SCqjAN5gzV9aIimoPVF9u tXm2gmRfO8ESEz9tCJXAGbN/oQeFAD3j1BNqPqzGsrdLdxxxLctUJd/8FRdvPdwK01T9 UZIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687209147; x=1689801147; 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=vlbPW/9a64l7E9zKncDfIqo+N9kap6U2HGHfiCdgBDk=; b=fqtDSuUPyKHmuQhIyTfGmHsr9ukjfgHp8ucETF1oKbzJJJ1QD5yID06OQ7+kXdajnb hMojXRdr5BpQi5AqmIrheJNUWugq1h4fm/7Ex7MkluK+cQk9Ze3CYnZ7hBcz+JA7UkGu GulnhHew/xA810CrhNM2vO+tZX91aOOPvu2v6l7picBUn4dBbssWEqV/nKJX+BZc8r2j ncbRaOJyvgf+djeNBTUWDPevFyFuAF9IBoRQdLGoUfGynIAq0GGqHQmA5itxsz4qe5/m dZh7GVxXiGc3RP58Wz3XusOfLqXZ7Udp+Q26JSAI8MYd8zVcYZj1nYSAB0fmQ1FqZ+qo B3Cg== X-Gm-Message-State: AC+VfDzEu+X8lYLn3Pby+k3HKiq0mfTPRaO/McA3lARolwUgTgDXOqZw M8mNhmGzPRhBXzMSqKz/XDZ5R4l+U4OS1NuxYCqYPA0C X-Google-Smtp-Source: ACHHUZ7d5Ve3t4ngu6/qfbUi/etgxXnkHS3dytndEJbo0pc6GOwKUyZzKNedA6uOQaUmTJkRXtIJHVzv5HX53/bAtrQ= X-Received: by 2002:a4a:ead0:0:b0:54f:629a:f581 with SMTP id s16-20020a4aead0000000b0054f629af581mr4963519ooh.7.1687209147411; Mon, 19 Jun 2023 14:12:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 19 Jun 2023 22:12:14 +0100 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000e4af7505fe81fda8" Subject: Re: [PHP-DEV] [RFC] Interface Default Methods From: davidgebler@gmail.com (David Gebler) --000000000000e4af7505fe81fda8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 19, 2023 at 9:53=E2=80=AFPM Rowan Tommins wrote: > On 19/06/2023 20:20, David Gebler wrote: > > Okay, thanks. That's really quite significant, since it changes the > feature > > to one which could allow changes made to interfaces to adversely impact > > existing clients of an interface without those clients changing a thing= . > > > As the RFC says, it introduces a form of multiple inheritance, and > inheritance in PHP doesn't make any such guarantee - to adapt your exampl= e: > > class A { > public function foo(): void { > $this->bar(); > } > } > > class B extends A { > public function bar(): void { > ... > } > } > > The job of detecting that class A doesn't define a contract for method > bar falls to static analysers, and the same would be true for default > implementations on interfaces. > > > > Sure, but in this example were B::bar() to be a private method, you would get a scope violation error. You would not if you were to use a trait, since any methods implemented in the trait would be executed in the same scope as the class using the trait. And that seems to be what's being proposed here for interface defaults. So my concern here is that when you use a trait, you know that what you're doing is effectively copy-and-pasting implementation into your class scope. You don't expect that when you declare a class to implement an interface. There's some degree of irony to me that we have another RFC, the Override attribute, which will introduce an engine-level check that could easily (and arguably should) be left to static analysis tools, yet we're talking here about introducing a mechanism where private methods on a class could be called by stealth by a mere interface. I'm not even sure static analysis tools would in their typical configuration pick up on a situation like this, either, since it could in this scenario sit in a vendor dependency and not your own code. I like the idea of this RFC - in fact it's one which has been near top of my wishlist for PHP language features for a long time - but I think this is an issue with the proposed implementation which at the very least warrants highlighting and discussion. --000000000000e4af7505fe81fda8--