Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120607 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82927 invoked from network); 16 Jun 2023 22:26:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jun 2023 22:26:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E15491804BE for ; Fri, 16 Jun 2023 15:26:51 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR 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-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 15:26:51 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-30c4c1fd511so946289f8f.1 for ; Fri, 16 Jun 2023 15:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; t=1686954410; x=1689546410; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hJ/WjkWnH4UyosiV0o+64xSraecs8otawH8QpjaCLf8=; b=BdTa53UWtEcpBvyBVlW2u9NkMnmuLfYCOlDEEJWi/th+DOqPZziwoZ+RFZU/3rHgUp MDGDSsaRqhNLJEy8fnY2sESrPQ/rk2PHzIL4JvjG4D/gN5/Gy0lNAzu71Oyk2QhKOgbR ibHoHAXdYpWHeTaK6JJpLoGNFs1oLXVCgW6xw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686954410; x=1689546410; 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=hJ/WjkWnH4UyosiV0o+64xSraecs8otawH8QpjaCLf8=; b=gIyqUE1TMZMDnL+2uBEl4zILLNukDknPY3q+ek0yPXo0MY39BxoyVFsLx9s39x8qcd tZds1nQrpAy80Up02nTJsymZtgIZuH2EH9+jurXcV3pyivcWtgo4+pEeM4C4wMUy4k+s PlfjtJYV0mcOVIsmTLtJlvoBggcv8qcVhZa2/JFvCjgpq3t5IGlsokZk3pQnXG6LLkbz fx62kk12PZl15jN2ode46eqLvBO1Vi1ML02qcoGPSqNRb5lDe+R+aKAHLaiOUiZmc0Nj Bs1/rgjxGr+erRxiNh3oSNSH4NTxmwneP4QBP0k9f5CtPC8eg9BT5Ik2lRKgnRMZ2waD CHCA== X-Gm-Message-State: AC+VfDzXyzDnAf34M+Ner11nF5mBX1dD8QZDawZdAHkD/vHRGye086GL ntJB0ZZych7Zz6U+0gzlqtoytkdDhA/nB+17rQL60+uiKmjgvRUEo96Afw== X-Google-Smtp-Source: ACHHUZ4jm0Yy0YmJoY3pO+ocTnhYaRxM7MrrKNkl7OjqqTXns+hxio2xfYFPRI84mXCAnZ4IJ2ZSL616WeXsJuGV+NY= X-Received: by 2002:adf:fdc4:0:b0:30a:df2d:dffc with SMTP id i4-20020adffdc4000000b0030adf2ddffcmr3075205wrs.53.1686954409750; Fri, 16 Jun 2023 15:26:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Fri, 16 Jun 2023 16:26:38 -0600 Message-ID: To: Deleu Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Interface Default Methods From: internals@lists.php.net ("Levi Morrison via internals") On Fri, Jun 16, 2023 at 11:51=E2=80=AFAM Deleu wrote: > > > On Thu, Jun 15, 2023 at 12:48=E2=80=AFAM Levi Morrison via internals 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(); > ``` > > > -- > Marco Deleu I'm not sure why you are saving `null` from `Interface1::method1()`'s implicit return and then returning it from inside `Class1::method1`, but yes, this is valid.