Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125969 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 D56BE1A00BD for <internals@lists.php.net>; Sat, 16 Nov 2024 00:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731717007; bh=qhPBpU+8up3vbvs43cWu/Eyut71mR3aG9nK6K4VtVQs=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=NhQRAlRxVZxZybh7/yoyIjGyuj/68/+k21SOv1Bkp/7r5in4QL1Kk2PYBbwdgYOL4 CytwFk4LNoeCjUhgV7JIqya8kFMMNl3i/rdrOyBPmmNtmY5ksR+Zx6UIyUKwuy7LB6 GRhgu7Syy5+skh9a5fs8sZ66Iw5+oZceAj885viGEtMyGx9rA18u2YNHeQF5QGEfgZ xlS1gwxNHl2cBE3JO1N2LJ50GN12TEDRKVG6374Ccnfn+3dtNsqupn4K5cr7mk7SYe T8hZ44da3MsFyCtmX9o0oYwlA22YK/npbibXXb1qcL2thBPBmNNmCoHIWZNLLDUtFJ Z5fnQYufpecsw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D1BA818006D for <internals@lists.php.net>; Sat, 16 Nov 2024 00:30:06 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <deleugyn@gmail.com> Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (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>; Sat, 16 Nov 2024 00:30:06 +0000 (UTC) Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-268d0979e90so168977fac.3 for <internals@lists.php.net>; Fri, 15 Nov 2024 16:27:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731716848; x=1732321648; darn=lists.php.net; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=W6D7ua9/Apq4jfH62d1288yPhEOIyocfxCuEO1UMqK8=; b=IwBN5kzebCJoYNZywCr6APfnuouku/XjI/Mb3hOaLNt/pybTehQOgN33QL6rdHeMqQ rRg1pRwoPrHTVM82EQvSg+3I1ZvAV8o9jnlJti7Cax35ZvBWA7MFgs/Kgob2w9D1VY9c fBSI3UpEScb0jD8kvnEo1cmSmxGYQhAjNBl19KfYXD94wuyqjzPMHy8B3t+KHzhj2ZSo OjdxkKzAe9IU9lpDBKL12DIVOs9PkfKlOyV1qIkPa1eU6LtiwNxDZwuIXPfEq9RUvF5s P3HRmGgqkHYWAupTjXQK2jsiYTUMmOMNBgm9uIWEvkJCtKekM7YNZHjod5KxbnKo4Z7A 0IRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731716848; x=1732321648; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W6D7ua9/Apq4jfH62d1288yPhEOIyocfxCuEO1UMqK8=; b=hmmkHRtEeAqGoEwGtlawuqcsbVnmmvAZrTA7jJ7VBhJQfxQqGPLEBzuA43MtQVxegs CCLG4aJOFlN2Xz2Ynuh85y4yRuQtkiWgbOjItWKFFbzJ7ByqfqMhARRaPTjBrQF3uJhF U06zW9Do1sMQ1JjR9rOgr4CyJZMTK8OTdlsVRtspGFfCBe5POfUM7OHev7YTKqiDGwAM 5DidxuW+xi8DnzBrNyfiL0KKRNttawobrCye2SGc7LtefRAsQ8rq74VW95hQYX2KJbT7 pl1K3mrYCjNCOOZP/6/MOFIt1yVawGPue6QrrsK5SpmyWdQiG8a7NuujRJgdBsm5r5m0 klKA== X-Gm-Message-State: AOJu0Yzpfqgk0rtwO3T9cTDQ6n8Ec8FwsOCXgxQ5jRC9uX43uXN3yju6 Razior5QovdVnJTaMh71ZhfAQo2/3AS6b5yafjdrIaVwbvbT5McSegSdag== X-Google-Smtp-Source: AGHT+IHMhM0rgQg31L4iWTm0DoNVQCQb57JLtedO1Z78FWVEFzmBhyxOwIPKzc/BRYIVtsQpsEF6ZQ== X-Received: by 2002:a05:6830:600c:b0:717:fbfe:52cd with SMTP id 46e09a7af769-71a77a2daa0mr910089a34.4.1731716847600; Fri, 15 Nov 2024 16:27:27 -0800 (PST) Received: from smtpclient.apple ([2804:18:891:d882:2158:e93c:a08f:7b5e]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71a78212bdfsm937125a34.61.2024.11.15.16.27.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Nov 2024 16:27:27 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-D9BF9992-F3C4-4EFA-9AE6-8D2E6D79A097 Content-Transfer-Encoding: 7bit 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 (1.0) Subject: Re: [PHP-DEV] Optional interfaces Date: Fri, 15 Nov 2024 21:27:14 -0300 Message-ID: <BFEF1623-CB82-48DC-8F63-4A649A277222@gmail.com> References: <b98dc200-02b7-468e-a96d-a38ce10656ed@app.fastmail.com> Cc: internals@lists.php.net In-Reply-To: <b98dc200-02b7-468e-a96d-a38ce10656ed@app.fastmail.com> To: Rob Landers <rob@bottled.codes> X-Mailer: iPhone Mail (22A3370) From: deleugyn@gmail.com (=?utf-8?Q?Marco_Aur=C3=A9lio_Deleu?=) --Apple-Mail-D9BF9992-F3C4-4EFA-9AE6-8D2E6D79A097 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > On 15 Nov 2024, at 20:42, Rob Landers <rob@bottled.codes> wrote: >=20 > =EF=BB=BF >> On Sat, Nov 16, 2024, at 00:34, Juris Evertovskis wrote: >> Hey all, >>=20 >> =20 >>=20 >> If you try to implement an interface that does not exist, you get the =E2= =80=98Interface =E2=80=9C%s=E2=80=9D not found=E2=80=99 error. Usually that=E2= =80=99s useful as it points to a code error. >>=20 >> =20 >>=20 >> However, sometimes we want our code to be compatible with an optional lib= rary. For example, my Expression class might be compatible with some ORM, bu= t it would also usable without it or with another ORM. This can already be a= ccomplished, but the solutions seems very workaroundish: https://stackoverfl= ow.com/questions/57996429/implements-interface-only-if-exists >>=20 >> =20 >>=20 >> Maybe the PHP itself should allow marking some interfaces as optional =E2= =80=94 such that they are discarded from the list if the interface class doe= s not exist? Here=E2=80=99s one way the syntax could look like: >>=20 >> =20 >>=20 >> class Expression implements MyInterface, ?OptionalInterface {} >>=20 >> =20 >>=20 >> interface EventDispatcherInterface extends ?PsrEventDispatcherInterfa= ce {} >>=20 >> =20 >>=20 >> BR, >>=20 >> Juris >>=20 >=20 > Hey Juris, >=20 > Is there some reason you cannot do this: >=20 > https://3v4l.org/hF1vr >=20 > =E2=80=94 Rob That seems to match what he shared on SO link? I think I opened this email with a strong negative feeling towards what woul= d be optional interface, but to be honest a syntax sugar where implements ?M= yInterface becomes something pretty close to what Rob shared doesn=E2=80=99t= sound bad, it=E2=80=99s just convenience. Unfortunately PHP is not keen on b= eing open to those. Overall, I dig it.= --Apple-Mail-D9BF9992-F3C4-4EFA-9AE6-8D2E6D79A097 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head><body dir=3D"auto"><div dir=3D"ltr"><br></div><div dir=3D"ltr"= ><blockquote type=3D"cite">On 15 Nov 2024, at 20:42, Rob Landers <rob@bot= tled.codes> wrote:<br><br></blockquote></div><blockquote type=3D"cite"><d= iv dir=3D"ltr">=EF=BB=BF<title></title><div>On Sat, Nov 16, 2024, at 00:34, J= uris Evertovskis wrote:<br></div><blockquote type=3D"cite" id=3D"qt" style=3D= "overflow-wrap:break-word;"><div class=3D"qt-WordSection1"><p class=3D"qt-Ms= oNormal">Hey all,<br></p><p class=3D"qt-MsoNormal"> <br></p><p class=3D= "qt-MsoNormal">If you try to implement an interface that does not exist, you= get the =E2=80=98Interface =E2=80=9C%s=E2=80=9D not found=E2=80=99 error. U= sually that=E2=80=99s useful as it points to a code error.<br></p><p class=3D= "qt-MsoNormal"> <br></p><p class=3D"qt-MsoNormal">However, sometimes we= want our code to be compatible with an optional library. For example, my Ex= pression class might be compatible with some ORM, but it would also usable w= ithout it or with another ORM. This can already be accomplished, but the sol= utions seems very workaroundish: <a href=3D"https://stackoverflow.com/questi= ons/57996429/implements-interface-only-if-exists">https://stackoverflow.com/= questions/57996429/implements-interface-only-if-exists</a><br></p><p class=3D= "qt-MsoNormal"> <br></p><p class=3D"qt-MsoNormal">Maybe the PHP itself s= hould allow marking some interfaces as optional =E2=80=94 such that they are= discarded from the list if the interface class does not exist? Here=E2=80=99= s one way the syntax could look like:<br></p><p class=3D"qt-MsoNormal"> = ;<br></p><p class=3D"qt-MsoNormal"> class Expression imple= ments MyInterface, ?OptionalInterface {}<br></p><p class=3D"qt-MsoNormal">&n= bsp;<br></p><p class=3D"qt-MsoNormal"> interface EventDisp= atcherInterface extends ?PsrEventDispatcherInterface {}<br></p><p class=3D"q= t-MsoNormal"> <br></p><p class=3D"qt-MsoNormal">BR,<br></p><p class=3D"= qt-MsoNormal">Juris<br></p></div></blockquote><div><br></div><div>Hey Juris,= <br></div><div><br></div><div>Is there some reason you cannot do this:<br></= div><div><br></div><div><a href=3D"https://3v4l.org/hF1vr">https://3v4l.org/= hF1vr</a><br></div><div><br></div><div id=3D"sig121229152">=E2=80=94 Rob<br>= </div></div></blockquote><br><div>That seems to match what he shared on SO l= ink?</div><div><br></div><div>I think I opened this email with a strong nega= tive feeling towards what would be optional interface, but to be honest a sy= ntax sugar where implements ?MyInterface becomes something pretty close to w= hat Rob shared doesn=E2=80=99t sound bad, it=E2=80=99s just convenience. Unf= ortunately PHP is not keen on being open to those.</div><div><br></div><div>= Overall, I dig it.</div></body></html>= --Apple-Mail-D9BF9992-F3C4-4EFA-9AE6-8D2E6D79A097--