Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125968 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 A4E471A00BD for ; Fri, 15 Nov 2024 23:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731714175; bh=wLIpxVSR4Qhmv+Z0p5N6svLJiNzOG7T44RpjHoDwTDg=; h=Date:From:To:In-Reply-To:References:Subject:From; b=l1DUsIaizbWx37nBV/lQCqwvwWSqesIUZ2geFOtxWEvnpw/v10OSRcYVzsWsOPxcx gMbsHV3+BqcnKXA/gTrHX8zArNwZ2TiAI8JbmfzKWkPAyQEeJ5gvQ8HuUnMSjEPi+t h/lXdNJV8ZEMKjGRacXLnyZnCJq04RsOtDTuuRtARs831IPwphUUkHAtawpfmigbCb D553nwcYz2fGRrhYHkGv1OezMZHaoLCJALd1HzLiKOoQYoPW6PVmKasDOm2n4+rTgr 4gQp1lo3qPlv+Hkrd6tku0d9PEsQaVHs2TSDNpe3AmFAxHyI9ssqw7AfQ4druG6HHX 3ZYTpflFW385g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B8D418004B for ; Fri, 15 Nov 2024 23:42:54 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (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, 15 Nov 2024 23:42:53 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id C141F1140135 for ; Fri, 15 Nov 2024 18:40:15 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Fri, 15 Nov 2024 18:40:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1731714015; x=1731800415; bh=2WyDtmsn/m c8o6Pe7w/wCV3Fqjcnv+7uKweAGPE/n5k=; b=IDNelPedQ3lTxgPJYPdj0Jz2rQ LpLAD4xI1iTrwWKXCRuoNxI56mpNmw/xHTJYgyzwKlqLeb0LkVI+3txJdYBW1LLj 2zCUmXCPLIkFfUnL5CZjQL+XPnejbxTcl916rfUFex21AUHFOgkZy1m6b6/K2Vju sIWeSaGJM5suu9T+2SeQxTNZA+PlyuEcfwWZvNGExzF0pqjzXOkL+ij4oFWkJx6I tWcDUNSl6Egp0dRA3z2EfdtkG4q1+y9yxgB9REeWld0h9Dx+oTXb8fHq4eVf2QcC /q2WW/8yHGxROojaU7KrYZgqdX6sk9BYF7ZzofKb+q4ADOyoNWIf7BqRMQtw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731714015; x=1731800415; bh=2WyDtmsn/mc8o6Pe7w/wCV3Fqjcnv+7uKwe AGPE/n5k=; b=F8qK5CwtCs4jksQWB51k2MlvrXj4gDKwJ+5cH/MaYhCXr6UdyTN bLXPzxdqgUDIeOXkFrBfz9n6NcCwzhbqViwYxzWNgFg5egMmd9YK/G61OSboTkjn u/LFZ0qXLzeX9kSx9D4t3HrQ1puGmHLTA7sjn1+otUCVpFaeXVSRPPpU/3MywMC0 pNtdz/J/KOKNfyrPMr5sYP2ksm0eytk/wigX2fTUz7cFhnbR6kdQYtPsF7N8uTIR vXJlyOZYDirvv8PBFQDpsj+JnkgysJCc8wVTlC2ey/tpLOAp0yv90zZj9VfR4w58 JPyhKg+b17Amzt+sr2cOyuuwnU02Wnb1xgw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdehgddufecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecuogfuuhhsphgvtghtffhomh grihhnucdlgeelmdenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerredtjeenucfh rhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvg hsqeenucggtffrrghtthgvrhhnpeektdejveeiieeljefhtdetleduteejgefhffduieei hfekfffhiedtkeevteettdenucffohhmrghinhepshhtrggtkhhovhgvrhhflhhofidrtg homhdpfehvgehlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtoh epuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhi shhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 681A7780069; Fri, 15 Nov 2024 18:40:15 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 16 Nov 2024 00:39:55 +0100 To: internals@lists.php.net Message-ID: In-Reply-To: <0a2f01db37b6$daba4e60$902eeb20$@glaive.pro> References: <0a2f01db37b6$daba4e60$902eeb20$@glaive.pro> Subject: Re: [PHP-DEV] Optional interfaces Content-Type: multipart/alternative; boundary=b0f86da2faa8437e8b0d73109de0be65 From: rob@bottled.codes ("Rob Landers") --b0f86da2faa8437e8b0d73109de0be65 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Nov 16, 2024, at 00:34, Juris Evertovskis wrote: > Hey all, > =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. Usuall= y that=E2=80=99s useful as it points to a code error. > =20 > However, sometimes we want our code to be compatible with an optional = library. For example, my Expression class might be compatible with some = ORM, but it would also usable without it or with another ORM. This can a= lready be accomplished, but the solutions seems very workaroundish: http= s://stackoverflow.com/questions/57996429/implements-interface-only-if-ex= ists > =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 cl= ass does not exist? Here=E2=80=99s one way the syntax could look like: > =20 > class Expression implements MyInterface, ?OptionalInterface {} > =20 > interface EventDispatcherInterface extends ?PsrEventDispatcherInte= rface {} > =20 > BR, > Juris Hey Juris, Is there some reason you cannot do this: https://3v4l.org/hF1vr =E2=80=94 Rob --b0f86da2faa8437e8b0d73109de0be65 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On= Sat, Nov 16, 2024, at 00:34, Juris Evertovskis wrote:

Hey all,

 

If you try to= implement an interface that does not exist, you get the =E2=80=98Interf= ace =E2=80=9C%s=E2=80=9D not found=E2=80=99 error. Usually that=E2=80=99= s useful as it points to a code error.

=  

However, sometimes we want our c= ode to be compatible with an optional library. For example, my Expressio= n class might be compatible with some ORM, but it would also usable with= out it or with another ORM. This can already be accomplished, but the so= lutions seems very workaroundish: https://stackover= flow.com/questions/57996429/implements-interface-only-if-exists
<= /p>

 

May= be 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 do= es not exist? Here=E2=80=99s one way the syntax could look like:

=

 

 =    class Expression implements MyInterface, ?OptionalInterface= {}

 

    interface EventDispatcherInterface extends ?PsrE= ventDispatcherInterface {}

 

BR,

Juris


Hey Juris,
Is there some reason you cannot do this:

=

=E2=80=94 Rob
--b0f86da2faa8437e8b0d73109de0be65--