Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120589 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44687 invoked from network); 15 Jun 2023 14:52:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jun 2023 14:52:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B4FBC1804F2 for ; Thu, 15 Jun 2023 07:52:22 -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=-0.7 required=5.0 tests=BAYES_05,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-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 ; Thu, 15 Jun 2023 07:52:22 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-3f8d258f203so17358535e9.1 for ; Thu, 15 Jun 2023 07:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; t=1686840741; x=1689432741; 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=4bNDe2a6dDaY29XB+++X59LMAo5+4a8eVZgeKMNSXbg=; b=FfpW1/nGz5J/5wlSHtAlHn/TCQ2qtRTrXKn3xPtnOHeYH47Uw4f20jEjTvrpIjdF/c whT0yqeXN3ZXxXnofWF6/o5TMG6HcBtGQW/7nGA5jTkEUggSiG6kxCb/yo4eIzM5i/O7 VNikj3U99TezqRvVxl9xNOTlH7Qx02sJmKj+w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686840741; x=1689432741; 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=4bNDe2a6dDaY29XB+++X59LMAo5+4a8eVZgeKMNSXbg=; b=kZHhEa3iiX4DZPhG81X6RiKGH3qmDUeShyKcCz0d5to5qk47bnl/WedxP6fQvcGL4W IPtrtjYdfE9r3V6i400Xmq+mJgStDoS0VLacXtdy4wAGeVPqoJaxlXBjAejgM1q79mbe Re1PrlJcNU4l/PrwjD2DpoOKjKpaKgsCpHeFCU3bVyAHC0jklEZTRhFOZ1BBayZvIDpH vM3lQoZkSOiMrpXnSaZ8oYsKsMVUwamUIMmackLxITjyJzBy1Q8dRjdq1XOzPVMG8q3u 46vc/wrQwdnoIRGQ9oHvJnp1DnLuu9X5wjgirTQbhYl8V4aUorTCyWMhaBzUIt4UnfzH hlLw== X-Gm-Message-State: AC+VfDxQ/bX8ffH8ba2edYiyVb/1CBbM06gvpHtlGLUtnHwFJxE3zY3u Jvgs1wXJwC1aOqQQlFXz0YtBCiiIKnUAUqRuN9hfOm7CKYszVdUUdmIBIQ== X-Google-Smtp-Source: ACHHUZ6ILHeRS6zP1JyStESu/9PnBcUsqoRv701EPruHYlOCl7/K7+iWaMf6rHWIFb2ztiuToK1DibQ5zbqjPdhGEWg= X-Received: by 2002:adf:f589:0:b0:309:419b:925d with SMTP id f9-20020adff589000000b00309419b925dmr10081973wro.70.1686840741139; Thu, 15 Jun 2023 07:52:21 -0700 (PDT) MIME-Version: 1.0 References: <648AAE1D.9070805@adviesenzo.nl> In-Reply-To: <648AAE1D.9070805@adviesenzo.nl> Reply-To: Levi Morrison Date: Thu, 15 Jun 2023 08:52:09 -0600 Message-ID: To: Juliette Reinders Folmer Cc: internals@lists.php.net 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 Thu, Jun 15, 2023 at 12:22=E2=80=AFAM Juliette Reinders Folmer wrote: > > On 15-6-2023 5:47, Levi Morrison via internals wrote: > > I am moving my RFC for interface default methods to discussion: > > https://wiki.php.net/rfc/interface-default-methods. > > There are two things I'm missing on an initial read of the RFC. > > > Adding a default implementation to an existing interface method will > not break existing code, because every existing usage has a higher > priority than the default. > > A: How would this work if the existing method in the implementing class > has a different function signature than the newly introduced method in > the interface ? > There are two aspects to this: > 1. What if the existing method has different parameters ? > 2. What if the existing method has the same parameters, but > different/incompatible parameter/return types ? You mis-interpreted what I was trying to say, so I'll try to clarify that first, and then secondly address your question. If there an existing interface, say: interface Interface1 { function method1(); } The RFC is saying that if you added a default implementation to `method1` without changing its signature at all, then that would not be a compatibility issue. All existing implementers have somehow implemented this method already, so adding a default will do nothing (it will be unused). As to your questions about incompatible signatures, it's not any different from any other interface method. If you add a new method to the interface, and it's not compatible with some existing method on an implementer, then it's a compatibility issue. That's not changing with default methods. What is changing is that if a new method is added to an interface, and it has a default implementation, it's way less likely to be a compatibility break, because we only have to worry about methods that share the same name. Without default methods, essentially all additions would be compatibility break. > B: How does the ability to add default method implementations to an > interface compare to providing an abstract class implementing the > interface and providing the default method implementations ? A key difference is that you can implement many interfaces, but can only extend a single class (abstract or not). For this reason, many contracts are formed with interfaces and relatively fewer with abstract classes. Well, that's my experience, anyway.