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 <internals@lists.php.net>; 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 <internals@lists.php.net>; 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: <jorg.sowa@gmail.com>
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 <internals@lists.php.net>; Fri, 14 Mar 2025 14:02:01 +0000 (UTC)
Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-223f4c06e9fso39364975ad.1
        for <internals@lists.php.net>; 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: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
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: <CAPTD5yE0aDgLuoB6fCQawrz9syWfGqFfq6_8taPCEUB5252oeQ@mail.gmail.com>
Subject: Re: [PHP-DEV] [RFC] [Discussion] Optional interfaces
To: Juris Evertovskis <juris@glaive.pro>
Cc: php internals <internals@lists.php.net>
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 <juris@glaive.pro=
> 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

<div dir=3D"ltr"><div><div><div><div><div>Hello Juris,<br></div>There is so=
me uncertainty for me on how this approach would work with namespaces.<br><=
br></div>Let&#39;s get this example:<br><a href=3D"https://3v4l.org/bI1Rj">=
https://3v4l.org/bI1Rj</a><br><br></div>I would expect to get the error mes=
sage that I forgot to insert `use Stringable;`. <br>But with your idea ever=
ything is fine. I don&#39;t like such ambiguity and I worry it may bring so=
me confusion to developers.<br><br></div>Kind regards,<br></div>Jorg</div><=
br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=
=3D"gmail_attr">On Sat, Dec 28, 2024 at 9:57=E2=80=AFPM Juris Evertovskis &=
lt;<a href=3D"mailto:juris@glaive.pro">juris@glaive.pro</a>&gt; wrote:<br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=3D"msg-17=
46763104004614392"><div lang=3D"LV" style=3D"overflow-wrap: break-word;"><d=
iv class=3D"m_-1746763104004614392WordSection1"><p class=3D"MsoNormal">Hi,<=
u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D=
"MsoNormal">I would like to propose a new syntax that let=E2=80=99s you imp=
lement an interface only if it exists.<u></u><u></u></p><p class=3D"MsoNorm=
al"><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal">`class MyClass extends ?=
OptionalInterface {}`<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0=
<u></u></p><p class=3D"MsoNormal">If the `OptionalInterface` exists, the cl=
ass implements it. If no such interface can be found, it is ignored.<u></u>=
<u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNo=
rmal"><a href=3D"https://wiki.php.net/rfc/optional-interfaces" target=3D"_b=
lank">https://wiki.php.net/rfc/optional-interfaces</a> <u></u><u></u></p><p=
 class=3D"MsoNormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal">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.<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u>=
</u></p><p class=3D"MsoNormal">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}`.<u></u><u></u></p><p class=3D"MsoN=
ormal"><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal">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.<u></u><u></u></p><p class=3D"MsoNormal"><u></u>=C2=A0<u></=
u></p><p class=3D"MsoNormal">Previous discussion: <a href=3D"https://extern=
als.io/message/125967" target=3D"_blank">https://externals.io/message/12596=
7</a><u></u><u></u></p><p class=3D"MsoNormal">WIP implementation: <a href=
=3D"https://github.com/php/php-src/pull/17288" target=3D"_blank">https://gi=
thub.com/php/php-src/pull/17288</a><u></u><u></u></p><p class=3D"MsoNormal"=
><u></u>=C2=A0<u></u></p><p class=3D"MsoNormal">Looking forward to your fee=
dback and suggestions!<u></u><u></u></p><p class=3D"MsoNormal">Juris<u></u>=
<u></u></p></div></div></div></blockquote></div>

--000000000000f4d86606304deaab--