Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126752 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 878B11A00BC for ; Fri, 14 Mar 2025 14:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741960922; bh=OuU1veDa3iblZn+8LUgEPqSzsmjfQDQ5eGbydxJFaQU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bGREFNLBdkCgwhdbdFq4EWS27hqr6GhzNu3NdF2rDlps4wFIhhm39hw473ua67zjQ 7JT+H8ICRbbYOVN/i02mwL8Bu0oI8xX5iAwKHo523Do2tBzvm3xWHzww0/4cmbUlS3 GJVNpp3iV5siGmxhp6BjNmDr0ud9eE7/SVCT0qm+MxNHTYsqjfDapXYQEboEOUIfMT YaPP0QNTIO0au91g5rXvVMHSlJ5RVZ0hRHYiMacdsiELJYO+69Jpju1kkIIgQyW5YK 9jZyHN0Cv8hcSQfwRVAK5Zibs60bJKDbgkZ4MsvqL5eUZjPMgp4spoD0PfyIDT3nCD yaqz/UDyzKtRg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66CED180072 for ; Fri, 14 Mar 2025 14:02:01 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 ; Fri, 14 Mar 2025 14:02:01 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-223f4c06e9fso39364975ad.1 for ; Fri, 14 Mar 2025 07:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741961073; x=1742565873; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OuU1veDa3iblZn+8LUgEPqSzsmjfQDQ5eGbydxJFaQU=; b=X5frdwwbSzUeU4i5pEfcSj3ym9ob06da//VFvYZeGfVaRMF1PASe2fFCOu6AvjkyIe qeaI7U+sglluTS4q7/X8+wdFn2WXBV4Nt4Iqxb8+gzCh18okjxMvJ3H1fSOXy1iZe5Er nsmc2Foi24NTx2DDNE0gaBUat/Ds/fbg+gs6N6cdnlhfC5Fuls6e8FE5dV8YFxspH8Vi rcSW9iFOM+u7H2TlmbmD0UbPk7O9MyACHCF+SV8EOKEyb5fFTeBO4uvEBIhayAgXCdG6 asmHgG0Nw0ctr3tjq3kbQEZdP5wH3lYEUhG5f2mMSrhs2FXqbQWVHCiPvHrrpYv8l9nL rtVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741961073; x=1742565873; 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=OuU1veDa3iblZn+8LUgEPqSzsmjfQDQ5eGbydxJFaQU=; b=EQ7nXP3j5OfAVGkLr58w+FebELHnWt6tEdKZEN4QCLI9ffUp0a1HEbKbL2gVuE37y9 VL1qmOcWI3yT1sy7cUKWRaMGAjA+x0+JliFcMnbJdxOgBABpgRVc5b3y9php4aIu/h6Q yYaPQgn0VWI6ZuWonTk7C9774ih5BvXyVoXX84WFIuDE17ONScClUMgHvvnz4j61E+q1 6DuIls0F7lFMriCLCXPCJP1gPAOx4lV+scLLLAkHzQI/puczobpdTf3dft6twTicNuet RVgaElsa1VsA9XLQxTn6cY4fLUSniqWy9CRRzGHorsIqnX6REv/hR85dyyozBXzR4A0o 3QAw== X-Gm-Message-State: AOJu0Yy1nty8cdAE7zJpKnmuVt9s/kwhqZITdDehMhJ6VrkM2q9rQpw3 N9Co+btGEn492YSrtvUVnBj071t3x1/0sMshpJTtP1EgOtp++DnvrtzUw0wwUvelCjAb70OgAsH sTdfpt5aFZcTKEGsjlTWP7RFy9XYT5GQk X-Gm-Gg: ASbGncuthXnGUXx3/p0k+Yx266ir7GE1Mb5H1ramA2OtonbvMNbqkOM7bRSfZD2neqk E5WLMYcP23q6zZJybQHx+b2PUbAkjKlqpHRa443+iPCqeFBL78Z5nWy5S7i4UalCy3Tao2ZM0bg l12Ae2ay+1iwgn71Y983mGBjh2V54= X-Google-Smtp-Source: AGHT+IGK++nrai5Hwrl4WKAgFs4fgg4DmyD1tME6FUh1zN9idUlQAzRIhiyoIDUPxiOt9CTK4hX8OlRUIOivYaz+o9M= X-Received: by 2002:a17:903:1cd:b0:21f:98fc:8414 with SMTP id d9443c01a7336-225c66e6f9fmr90001555ad.26.1741961072791; Fri, 14 Mar 2025 07:04:32 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <087a01db596a$e7525660$b5f70320$@glaive.pro> In-Reply-To: <087a01db596a$e7525660$b5f70320$@glaive.pro> Date: Fri, 14 Mar 2025 15:04:21 +0100 X-Gm-Features: AQ5f1JotyC5gDqrq_FE5YRY7LJU5D9YIhDakwHKsFeE9NnYesYpLhqQ8DGsf3Fw Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Optional interfaces To: Juris Evertovskis Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f4d86606304deaab" From: jorg.sowa@gmail.com (Jorg Sowa) --000000000000f4d86606304deaab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Juris, There is some uncertainty for me on how this approach would work with namespaces. Let's get this example: https://3v4l.org/bI1Rj I would expect to get the error message that I forgot to insert `use Stringable;`. But with your idea everything is fine. I don't like such ambiguity and I worry it may bring some confusion to developers. Kind regards, Jorg On Sat, Dec 28, 2024 at 9:57=E2=80=AFPM Juris Evertovskis wrote: > Hi, > > > > I would like to propose a new syntax that let=E2=80=99s you implement an = interface > only if it exists. > > > > `class MyClass extends ?OptionalInterface {}` > > > > If the `OptionalInterface` exists, the class implements it. If no such > interface can be found, it is ignored. > > > > https://wiki.php.net/rfc/optional-interfaces > > > > The need to declare compatibility with a certain interface without > requiring the interface itself comes up when you=E2=80=99re writing code = that > should work with various versions of other libraries or PHP itself and wh= en > a library provides interoperability with some other library or a PHP > extension, but does not require it. > > > > Although this would mainly be used by library developers, the consumers o= f > those libraries would also benefit as this syntax would clearly communica= te > the intention of optional interoperability. IDEs and static analysis tool= s > could also have easier time with `?OptionalInterface` instead of class > definitions inside an `if (interface_exists(=E2=80=A6)) { =E2=80=A6 } els= e {=E2=80=A6}`. > > > > I=E2=80=99ve not entirely sure about the naming as an =E2=80=9Coptional i= nterface=E2=80=9D feels > like an oxymoron. I=E2=80=99ve also considered names like non-required in= terfaces, > conditional interfaces, optional/conditional implementation or even soft > interfaces/soft implementation. Please let me know if the naming itself > bothers you. > > > > Previous discussion: https://externals.io/message/125967 > > WIP implementation: https://github.com/php/php-src/pull/17288 > > > > Looking forward to your feedback and suggestions! > > Juris > --000000000000f4d86606304deaab Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Juris,
There is so= me uncertainty for me on how this approach would work with namespaces.
<= br>
Let's get this example:
= https://3v4l.org/bI1Rj

I would expect to get the error mes= sage that I forgot to insert `use Stringable;`.
But with your idea ever= ything is fine. I don't like such ambiguity and I worry it may bring so= me confusion to developers.

Kind regards,
Jorg
<= br>
On Sat, Dec 28, 2024 at 9:57=E2=80=AFPM Juris Evertovskis &= lt;juris@glaive.pro> wrote:
<= /div>

Hi,<= u>

=C2=A0

I would like to propose a new syntax that let=E2=80=99s you imp= lement an interface only if it exists.

=C2=A0

`class MyClass extends ?= OptionalInterface {}`

=C2=A0=

If the `OptionalInterface` exists, the cl= ass implements it. If no such interface can be found, it is ignored.=

=C2=A0

https://wiki.php.net/rfc/optional-interfaces

=C2=A0

The nee= d to declare compatibility with a certain interface without requiring the i= nterface itself comes up when you=E2=80=99re writing code that should work = with various versions of other libraries or PHP itself and when a library p= rovides interoperability with some other library or a PHP extension, but do= es not require it.

=C2=A0=

Although this would mainly be used by librar= y developers, the consumers of those libraries would also benefit as this s= yntax would clearly communicate the intention of optional interoperability.= IDEs and static analysis tools could also have easier time with `?Optional= Interface` instead of class definitions inside an `if (interface_exists(=E2= =80=A6)) { =E2=80=A6 } else {=E2=80=A6}`.

=C2=A0

I=E2=80=99ve not enti= rely sure about the naming as an =E2=80=9Coptional interface=E2=80=9D feels= like an oxymoron. I=E2=80=99ve also considered names like non-required int= erfaces, conditional interfaces, optional/conditional implementation or eve= n soft interfaces/soft implementation. Please let me know if the naming its= elf bothers you.

=C2=A0

Previous discussion: https://externals.io/message/12596= 7

WIP implementation: https://gi= thub.com/php/php-src/pull/17288

=C2=A0

Looking forward to your fee= dback and suggestions!

Juris=

--000000000000f4d86606304deaab--