Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126753 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 61FE41A00BC for ; Fri, 14 Mar 2025 14:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741962185; bh=IvAtSelepz9CP+whHz2X6vmMPdduwwKW1dNiPxKkn4w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=D3N44rfQT+lIa7m6K3gI9B4bL+ke2LueBMcRUKEEXc5KPE8fWIpOEtUpMP6h2D7sB gIXUU1lmlWL5D6HZAbbItgqI7G96xXR4q6zI/NuOMwIwsDNB1R6UF7T/WZzQdGsI6B V1dxrn56aRGqOGEJoEzSKJR75ztRvfAhxBQjyMwOfxfTrVd5NE4pDLdF9oSIzsyk7V UVdz5RhEI61be9X41/u9pA42PvB4SCy01RdVGdZ8qW447Y5v+pUxnbUrC/z9LdAUDY TYxZGqNDoHthAWufDvB4wMDuFRPhpd5PCEf/Nw8oWEmfAVPwR7rs7PXoTTDtQlxKwW gzTZ7RFFGE0zQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 23CFA18007F for ; Fri, 14 Mar 2025 14:23:04 +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-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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:22:53 +0000 (UTC) Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4769aef457bso24418841cf.2 for ; Fri, 14 Mar 2025 07:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741962326; x=1742567126; 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=0UWLdYc3CixC5rn326nBYM7vK3m3rHIEp5sNAqmUz6U=; b=Ka3m5lZ+gZN3QC2WWxh2v2OVJhwpmyJ+do/t2hUajILKz3bAnQni0/txiMtMRWo3Wa x9T+lWe4fE7GjTNdMzAw+itxc2plMCCnmJmYHOZPswLWXe4IONOb93LLnMyzitCsHR4C BAR4PHYfZxfos8ZdJttTTdFHpNoqviq953h6wDxQcloagjMovxt2s4TYZPtl6HsixP8S vhq4UG+g6EUOMokK9q00X7m/b8lkXPD+b4veXF7+YKJHIq0NfssVuvKDbzOELJggV6MC zEda7HAQXY7wK6fdR+uJ91H7RY4ULKFqpf7r5WMpenNcTUosziMkZx1QqRZk/VYm+bCW r0Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741962326; x=1742567126; 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=0UWLdYc3CixC5rn326nBYM7vK3m3rHIEp5sNAqmUz6U=; b=FETUiwfcAqfq3R/njDf6XrH+O5vFvVeYNrRRr81rDITUcRS1iVfS2GgxmJiohv/dcV UssV0lY+Zca07ZmyaFD1GxcmYKn/6yE6fEjV8BmnAV9v8dKBd20Puvgdsctqy6IslDGp DotYUGjCSk6Xx7Uz1+9iAqdpS/LDLNmMYNjkxXltXiDlyNK4wmpnpYhFjVHpaSX1MYzz XSl37Eze00Ncr0C3ClgdQQRNejKbJSsfTW9VfJk2pAMPyP8coC+PvFx6fJdrXaOZmYcu NIKr0UCwwkzU36tHp0jzs+INyUDXvrH4FuJ50ETCXV87hxms7oo3iZB/Dc2WHUItsH0W /ZLg== X-Forwarded-Encrypted: i=1; AJvYcCUxXS+CZEVhPUPBeAcLtFYEXaEp/eLj9951bDIYoKAZDfGzK7yt2w8mq0qvQ0XlgA/l9SFdGnDYtRM=@lists.php.net X-Gm-Message-State: AOJu0Yzp2U1yc68jVmtyc3glLSMIqH2frUa41jEoJ8AalKx05wffISge phtk0jmfd4/oi97CK9HugZuxTXwDKEfpHzWcFW1ZTg673oHB3+MPdJlBOqLIF91/BNU6D25VXYq CZLfn967emlPVlx83Sn+XvTE7c+o= X-Gm-Gg: ASbGncvJLcYoqio9IEQVGXt5tl2DxKBOdoIfjOCSH6bKW/1pTNMimYooDIlRWIKp40L HdRJQukzg3ugKLSXz7rTYhXko1NX43DY0Dvvbs9vHEq89TUlQF+IBKxUfeaLIkf61Lzr0vPFnzP pfFb15foksBYfQ0hnTgyyD/4Z5VSZ1H55VshmL X-Google-Smtp-Source: AGHT+IHKYx/k1Gb1NzoyjjvoNWCzJXr/mng2tKit5k4F5M9KGGJ3hPsp2zwoimvH+1JyLDIsew8PLppX6TWRE6GCAyg= X-Received: by 2002:a05:622a:118d:b0:476:6215:eb08 with SMTP id d75a77b69052e-476c813f0b8mr25630521cf.22.1741962325912; Fri, 14 Mar 2025 07:25:25 -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: Date: Fri, 14 Mar 2025 17:24:48 +0300 X-Gm-Features: AQ5f1JodZvkCzj4Ey3ZVNf4DtIWPAmk7Q7JQvkUNKCzRfRotYlCKkufSDP08p38 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Optional interfaces To: Jorg Sowa Cc: Juris Evertovskis , php internals Content-Type: multipart/alternative; boundary="000000000000a5f05606304e3512" From: dev.999.victor@gmail.com (Viktor Khramov) --000000000000a5f05606304e3512 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Juris. I have a question about this feature. At the example blow interface A > { > public function x(Foo $foo); > } > > interface B > { > public function x(Bar $foo); > } > > class Test implements ?A, ?B > { > } > what would happen if both interfaces existed? =D0=BF=D1=82, 14 =D0=BC=D0=B0=D1=80. 2025=E2=80=AF=D0=B3. =D0=B2 17:08, Jor= g Sowa : > 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 w= hen >> 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 >> of those libraries would also benefit as this syntax would clearly >> communicate the intention of optional interoperability. IDEs and static >> analysis tools could also have easier time with `?OptionalInterface` >> instead of class definitions inside an `if (interface_exists(=E2=80=A6))= { =E2=80=A6 } else >> {=E2=80=A6}`. >> >> >> >> I=E2=80=99ve not entirely 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 i= nterfaces, >> 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 >> > --000000000000a5f05606304e3512 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Juris.

I have a question about this feature.
At the example blow

interface A
{
=C2=A0 =C2=A0public function x(Foo $foo);
}
interface B
{
=C2=A0 =C2=A0public function x(Bar $foo);
}
class Test implements ?A, ?B
{
}
<= br>what would happen if both interfaces existed?


=D0=BF=D1=82, 14 =D0=BC=D0=B0=D1=80. 2025=E2=80=AF=D0=B3. = =D0=B2 17:08, Jorg Sowa <jorg.sow= a@gmail.com>:
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 expe= ct 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 regard= s,
Jorg

On Sat, Dec 28, 2024 at 9:57=E2=80=AFPM Juris Evertovskis &= lt;juris@glaive.pro> wrote:

Hi,

=C2=A0

I would lik= e to propose a new syntax that let=E2=80=99s you implement an interface onl= y if it exists.

=C2=A0

`class MyClass extends ?OptionalInterface {}`

=C2=A0

If the `OptionalInterface` exists, the class implements it. If n= o such interface can be found, it is ignored.

=C2=A0

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

=C2=A0

The need to declare compatibil= ity with a certain interface without requiring the interface itself comes u= p when you=E2=80=99re writing code that should work with various versions o= f other libraries or PHP itself and when a library provides interoperabilit= y with some other library or a PHP extension, but does not require it.

=C2=A0

Although this would mainly be used by library developers, the consu= mers of those libraries would also benefit as this syntax would clearly com= municate the intention of optional interoperability. IDEs and static analys= is tools could also have easier time with `?OptionalInterface` instead of c= lass definitions inside an `if (interface_exists(=E2=80=A6)) { =E2=80=A6 } = else {=E2=80=A6}`.

=C2=A0=

I=E2=80=99ve not entirely sure about the nam= ing as an =E2=80=9Coptional interface=E2=80=9D feels like an oxymoron. I=E2= =80=99ve also considered names like non-required interfaces, conditional in= terfaces, optional/conditional implementation or even soft interfaces/soft = implementation. Please let me know if the naming itself bothers you.=

=C2=A0

Previous discussion: https://externals.io/message/125967

=

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

=C2=A0

=

Looking forward to your feedback and suggestions!=

Juris

--000000000000a5f05606304e3512--