Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120605 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64918 invoked from network); 16 Jun 2023 17:51:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jun 2023 17:51:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE9901804DF for ; Fri, 16 Jun 2023 10:51: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=-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: Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 16 Jun 2023 10:51:33 -0700 (PDT) Received: by mail-vk1-f181.google.com with SMTP id 71dfb90a1353d-46e9ce7870dso147099e0c.1 for ; Fri, 16 Jun 2023 10:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686937892; x=1689529892; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nhWkV4BsGdzzAcTIXNv2Nu4+jjwY8ZHAaEeWrB4hnNA=; b=fnYUPSAMIvNrx5N9hkZMYA7n8bCNYAHEA9rtp6lqubn9H11LvcRiFg91HNQQ9Sp1VP q0OhBV25fC/RQGrIkchfNoHmUbbC92oaEd98ZC+oOEuhx67ge1j94fyjUd2U0Sry4AdH nwN9i0B6XZp9nVFX+c6yJYBLUTOqFaDqdk8fIF6yXuZN5RYuylzugHteTRsPGHsK75gt 5fYgCmxpID29KqNyxfsCtXb7N0nSuxCPhMDx6MSovAA4sEe57WaTTbWg34HLyil9v85k 90+5glWKmPIUu1oXC5MoHATFJ5sLrNrZLtfawJBOggiSVOCA9TsaxQcXeW6u4TkNhOHY oQmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686937892; x=1689529892; 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=nhWkV4BsGdzzAcTIXNv2Nu4+jjwY8ZHAaEeWrB4hnNA=; b=RcdVYEyIEK28BMWYuAKN8iT7lJ55KrmtA1/XVLKVlMVtwPjbQClOtcJhn4uPO/DQhY 4b/zBM1YSkdjFOgII32yglgcfRowmUPEyjTTAiNFFUzG2xKaNw5s0fkz1dc1J9mfZSlC iOx8dHSkqmhukbvutMLFzAMDMfFO5FwXS9M0r0faBJT7Ccea0s+WhQsoYdWpIJHrxQD6 VxgSlMnmh0YnUgHUuuK3r2oepddB5ou7r/C7OSP4gIuLW/F/oi1XYzZ8+Pi5RZvkdJfn 9E94j0LyEeYV4MfgvA8pQa9Nx7+XtMBmpDl2RHM2CTuF6W0tyrtQQiGCBKdvge7mq7Xc RsFw== X-Gm-Message-State: AC+VfDyOc7aYjLQCcl6Mm6Wu2u/RNsnArCWx1BIQPUaezu9icvNCzWU0 sWJ4udxGvCBLLpcqZndl5WmyFaPLchB/jtro3Gg= X-Google-Smtp-Source: ACHHUZ7Q9dBrzYYDimprkpepQgpCA3v2hc9ItqSsV3tgeS3Gn0d8s28CVAiua8+pluGVHjAvbV43JoXErNInuytI6oU= X-Received: by 2002:a05:6122:10cd:b0:471:5239:5976 with SMTP id l13-20020a05612210cd00b0047152395976mr1063690vko.1.1686937892446; Fri, 16 Jun 2023 10:51:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 16 Jun 2023 14:50:56 -0300 Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d667aa05fe42d56c" Subject: Re: [PHP-DEV] [RFC] Interface Default Methods From: deleugyn@gmail.com (Deleu) --000000000000d667aa05fe42d56c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 15, 2023 at 12:48=E2=80=AFAM Levi Morrison via internals < internals@lists.php.net> wrote: > Hello, PHP Internals, > > I am moving my RFC for interface default methods to discussion: > https://wiki.php.net/rfc/interface-default-methods. > > This can be a useful tool for a few reasons: > 1. It can make implementing an interface easier when certain methods > can be implemented by other methods in the interface. For example, if > `Countable` had an `isEmpty(): bool` method, it could be implemented > by doing `$this->count() > 0`. Of course, if an implementation can be > more efficient, they are still free to implement it how they want. > 2. It can mitigate BC breaks in some cases. It's somewhat common for > authors to want to expand new methods onto existing interfaces over > time. Although this would still be a BC break, it moves it from a > massive change (every single implementor must add something, even if > it's a stub, or it will fail to compile) to a naming collision issue > only (only classes which already had a method of the same name will > fail to compile). > > There is prior art for this feature in both Java and C#. There may be > other languages, but I was aware of at least these. > > Note that the RFC links to a partial implementation. If there are two > or more interfaces with default methods of the same shape (name, args, > etc) and a class implements both interfaces and doesn't provide a > concrete implementation, which default implementation should be > chosen? There is a proposal for resolving this in some cases which is > modelled after Java's implementation, but it isn't implemented. > > Thank you for your time. I look forward to productive feedback. > > Levi Morrison > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > A question just occurred to me. Building up on the example of the RFC, is the following snippet valid and would it behave as expected? ``` interface Interface1 { function method1() { echo __METHOD__ . "\n"; } } interface Interface2 { function method1() { echo __METHOD__ . "\n"; } } class Class1 implements Interface1, Interface2 { function method1() { $result =3D Interface1::method1(); Interface2::method1(); return $result; } } $result =3D (new Class1())->method1(); ``` --=20 Marco Deleu --000000000000d667aa05fe42d56c--